HTTP::Server

inkdroid on 2004-03-05T16:32:11

Gotcha, so this is python:

import BaseHTTPServer

class HelloWorldServer( BaseHTTPServer.BaseHTTPRequestHandler ): def do_GET( self ): self.send_response( 200 ) self.send_header( "Content-type", "text/html" ) self.end_headers() self.wfile.write( "hello world" )

server = BaseHTTPServer.HTTPServer( ( '', 8080 ), HelloWorldServer )

while 1: try: server.handle_request() except: break



Creates a non-forking HTTP server which responds to requests with "Hello World". I could get used to that. Right tool for the right job and all.


From HTTP::Daemon's manpage (same thing)

merlyn on 2004-03-05T16:49:24

         use HTTP::Daemon;
         use HTTP::Status;

         my $d = HTTP::Daemon->new || die;
         print "Please contact me at: <URL:", $d->url, ">\n";
         while (my $c = $d->accept) {
             while (my $r = $c->get_request) {
                 if ($r->method eq 'GET' and $r->url->path eq "/xyzzy") {
                     # remember, this is *not* recommened practice :-)
                     $c->send_file_response("/etc/passwd");
                 }
                 else {
                     $c->send_error(RC_FORBIDDEN)
                 }
             }
             $c->close;
             undef($c);
         }

Re:From HTTP::Daemon's manpage (same thing)

inkdroid on 2004-03-05T16:53:30

Whew, thanks Merlyn. Pythonic episode over :)