NAME ^

['HTTP' ; 'Daemon'] - A Simple HTTPD Server

SYNOPSIS ^

  load_bytecode "HTTP/Daemon.pir"
  opts = new .Hash
  opts['LocalPort'] = 1234
  opts['LocalAddr'] = 'localhost'
  clid = find_type ['HTTP'; 'Daemon']
  d = new clid, opts
  unless d goto err
  d.'run'()

TODO ^

A lot. The code is by now just an objectified version of httpd.pir.

SEE ALSO ^

RFC2616, examples/io/httpd2.pir

AUTHOR ^

Leopold Toetsch <lt@toetsch.at> - some code based on httpd.pir.

Class HTTP; Daemon ^

A HTTP server class.

Functions ^

_onload

Called from load_bytecode to create used classes.

req_handler(pio, conn)

Called from the asynchronous select code, when data are ready to read at the pio.

Methods ^

__init(args)

Object initializer, takes a hash argument to initialize attributes, which are:

LocalPort

Port number to listen.

LocalAddr

Address name or IP number to listen.

debug

Turn on internal diagnostic messages, printed to stderr.

parrot-docs

Redirect to and serve files from docs/html.

socket()

Get connected server socket.

opts()

Get server options.

url(?init?)

Get or set server url, aka document root

__get_bool()

Vtable method, called from the if or unless opcode. Returns true, if the daemon object is listening on a socket, that is if the initialization went ok.

run()

Main server runloop.

_write_logs()

Called from server runloop. Write log files (currently to stdout only).

debug(...)

If debugging is on, concat passed arguments and write that string to stderr.

log(...)

Concat passed arguments and schedule the string for logging.

_select_active()

Create a select event for all active connections. Called from server runnloop.

_del_stale_conns()

Not yet used method to delete old connections for the active set. Called from server runnloop.

new_conn(pio)

Add pio to the list of active connections.

accept_conn()

Accept a new connection and call new_conn on the accepted socket.

del_conn(conn)

Delete connection from the active list

exists_conn(conn)

Return true, if the given connection is already active.

Class HTTP; Daemon; ClientConn ^

A class abstracting client connections.

Methods ^

init_pmc(pio)

Create a new connection object with the given socket pio.

socket()

Get connection socket.

server(?srv?)

Get or set server object.

timestamp(?ticks?)

Get or set the timestamp of this connection.

get_request

Read client request, return Request obj. Currently only GET is supported.

_read

Internal method to read from the client. It returns a request string.

send_respons(resp)

Send the response back to the client. Argument is a response object.

send_file_respons(url)

Slurp the url and send the response back to the client. TODO doc CGI urls.

check_cgi(url)

Check if a request url is a CGI request. If yes, return the reulst of the CGI invocation.

Utility functions ^

to_string

Doomed.

urldecode(s)

Return %-unescaped string of url string.

hex_to_int

Called from above to convert a hex string to integer.

make_query_hash

Split a query string at '&' and return a hash of foo=bar items. The hash keys and values are urldecoded already.

Class HTTP;Message ^

Base class for Request and Response Messages.

Methods ^

__init()

Create a new Message object.

headers()

Return an OrderedHash of message headers.

content(?s?)

Set or get the message contents.

parse(s)

Parse the given request string into header and content attributes of the Message object.

Class HTTP;Request isa HTTP;Message ^

Handles client requests.

Methods ^

method()

Return the request method. Currently just 'GET' or '' is returned.

__get_bool()

Returns true, if the request has at least one header.

uri()

Return the uri of the request.

Class HTTP;Response isa HTTP;Message ^

Methods ^

code(c)

Create initial code response line. This has to be called first to create header response items.

header(h => v, ...)

Append the given keyed items to the response headers.

XXX shall this be actually push_header?

as_string()

Return stringified version of the response object, ready for returning to client.

# Local Variables: # mode: pir # fill-column: 100 # End: # vim: expandtab shiftwidth=4:


parrot