mcbig + elkaca = filda ZeroPage.cz
cs en 

Poor Http Server

Poor Http Server is standalone http server, which is designed for using python web applications. Unlike other projects, this is not framework, but single server type application. It is not depended on another special technologies or frameworks, only on base python library and it provides base API for making python web applications.

Why choose Poor Http

  • Stand alone server application.
  • It's depends only on base Python library, there is no need to other special frameworks or libraries.
  • Base API for writing python web applications allows running applications under self users.
  • Python modules are still stores in memory, so new request are serves very quickly. [Single and Threading mode]
  • Server could runs in threading and forking mode, so more request could be serves in same time.
  • Easy configuration by ini file, which could be use to configuration of web application.
  • Error and Access Log
  • Standard error handlers: 500 Internal Server Error, 400 Not Found, 302 Found (redirect), etc.
  • API variability
  • Base file transport (css, txt, png files)
Server is not, and it could be not classic http server. It does not support cgi, directory listing or virtual hosting (HTTP/1.1 header). It goes well where it's better run python application in server mode. It is no need to other http server, but it is recommending to use real http server as proxy server before this application. Poor Http server application could be use as html gui of some system application for example too.

Server installation

Installation is so easy, just download, unpack, copy and run. Server can't support hosting of more then one application. So each application must have self installation.

Download - changelog

Installation could look like this:
$ tar xjf poorhttp-20091124.tar.bz2
$ mkdir -p /srv/run /srv/log /srv/app /srv/www
$ mv poorhttp /srv/
$ mv etc /srv/
$ mv init.d/poorhttp /etc/init.d/
$ /etc/init.d/poorhttp start

Hello world application

There must be two files at least. First file with required name is dispatch_table.py. It could contains function setreq, dict errors and must contains dict handlers. Function setreq is calls in each request and it sets environment of request. Dict handlers contains urls, HTTP methods and functions, which defines which function from which module is calls on url by methods. Error dict contains pairs of uri and error functions.
Other files (modules) contains functions listed in file dispatch_table.py. Return value of function is http code. Functions could ends by exceptions like in mod_python. Hello world application example:

dispatch_table.py:
# dispatch_table.py    
import http
import main

def setreq(req):
pass

errors = {
http.HTTP_NOT_FOUND: main.not_found,
}

handlers = {
# uri: (method, function )
'/': (http.METHOD_GET, main.hello),
'/bye': (http.METHOD_GET, main.bye),
}
main.py:

# main.py

import http

def hello(req):
req.content_type = "text/html"
req.write("<b>Hello world</b>")
return http.DONE

def bye(req):
req.content_type = "text/plain"
 content = "Bye bye"
raise http.SERVER_RETURN http.OK

def not_found(req):
req.content_type = "text/html"
req.status = http.HTTP_NOT_FOUND
req.write("<b>Page %s not found</b>" % req.uri)
return http.DONE

Mini documentation

All functions, which are called by poor http server to serve the request must have one input parameter (req). This parameter is Request object. Request class is defined in file http/classes.py.

Function can return http code or it can stop with exception SERVER_RETURN with http code.

Dict handlers in file dispatch_table.py have structure 'uri': (method,  function). Method could be one of method defined in http/enums.py.

If you want to initialize some object ones, just do it in dispatch_table.py module, which is called only if is change. Or you could use env module, which have some object initialized once at start time.

There is session implementation in Poor Http API.There is three classes:
  • Session - data is store at client side in browser, and it is send with each cookie.
  • MCSession - data is stored in Memcache Server, which must be configured.
  • FileSession - data is stored at server side in file like in PHP. [This class is not implement yet!]
Server configuration is documented in example ini file, eventually in python source code.

BSD Licence

Copyright (c) 2009, Ondrej Tuma. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Main menu



boincstats

E-mail: mcbig at zeropage dot cz, pgp: id 13A76FF2 & fingerprint CEE2 1B8E 88F2 3B1B CF5B 40DD 0663 483F 13A7 6FF2
Jabber: mcbig at jabber.cz, status: offline ;  Twitter: mcbig_cz;  rss: články, twitter
            
BlackMouse falias powered by Vim test on netsurf Webkit test on SeaMonkey Suite test on Firefox test on Opera UTF8 encoded Přidej na Seznam optimalizace PageRank.cz