HTTP;Daemon - A Simple HTTPD Server
load_bytecode "HTTP/Daemon.pbc" opts = new 'Hash' opts['LocalPort'] = 1234 opts['LocalAddr'] = 'localhost' d = new ['HTTP';'Daemon'], opts unless d goto err d.'run'()
The code is by now just an objectified version of httpd.pir.
Leopold Toetsch <email@example.com> - some code based on httpd.pir.
A HTTP server class.
Called from load_bytecode to create used classes.
Called from the asynchronous select code, when data are ready to read at the pio.
Object initializer, takes a hash argument to initialize attributes, which are:
Get connected server socket.
Get server options.
Get or set server url, aka document root
Object is true if the daemon is listening on a socket, that is if the initialization went ok.
Main server runloop.
Called from server runloop. Write log files (currently to stdout only).
If debugging is on, concat passed arguments and write that string to stderr.
Concat passed arguments and schedule the string for logging.
Create a select event for all active connections. Called from server runnloop.
Not yet used method to delete old connections for the active set. Called from server runnloop.
pio to the list of active connections.
Accept a new connection and call
new_conn on the accepted socket.
Delete connection from the active list
Return true, if the given connection is already active.
A class abstracting client connections.
Create a new connection object with the given socket pio.
Get connection socket.
Get or set server object.
Get or set the timestamp of this connection.
Read client request, return Request obj. Currently only
GET is supported.
Internal method to read from the client. It returns a request string.
Send the response back to the client. Argument is a response object.
url and send the response back to the client. TODO doc CGI urls.
Check if a request url is a CGI request. If yes, return the result of the CGI invocation.
Return %-unescaped string of url string.
Called from above to convert a hex string to integer.
Split a query string at '&' and return a hash of foo=bar items. The hash keys and values are urldecoded already.
Base class for Request and Response Messages.
Create a new Message object.
Return an OrderedHash of message headers.
Set or get the message contents.
Parse the given request string into
content attributes of the Message object.
Handles client requests.
Return the request method. Currently just 'GET' or '' is returned.
Returns true, if the request has at least one header.
Return the uri of the request.
Create initial code response line. This has to be called first to create header response items.
Append the given keyed items to the response headers.
XXX shall this be actually push_header?
Return stringified version of the response object, ready for returning to client.
# Local Variables: # mode: pir # fill-column: 100 # End: # vim: expandtab shiftwidth=4 ft=pir: