Bernardo The Smallest HTTPD Ever!
April 18, 2009 | Filed Under Utils | 1 CommentSometimes I need an HTTP Server that allows me to run C or Python code or other scripts, and I need something that require 0 seconds of configuration. So I’ve decided to write a small httpd that does this work. (Use only for your test, not on a work machine!).
Bernardo (The name is inspired by the Zorro’s servant) is a small HTTPD (Less that 200 lines of code) that allows you to Execute C, Python, Perl, PHP code or just “display” a file.
The Usage is Very simple: bernardo-httpd
And now a simple code Example. You need to complete the HTTP Response Headers and then you can output your data. http://localhost:8080/test.py will display the “Hello Python” page.
#!/usr/bin/env python
import os
if __name__ == '__main__':
print "Content-Type: text/html"
print
print "<html>"
print "<head><title>Hello Python</title></head>"
print "<body>"
print "<h1>Hello Python</h1>"
print "<p><b>Request Method</b>: ", os.environ['REQUEST_METHOD']
print "<p><b>Query String</b>: ", os.environ['QUERY_STRING']
print "</body>"
print "<html>"
The Source Code is Available Here: Bernardo HTTPD Source Code.