[Web-SIG] wsgiref questions

Sylvain Hellegouarch sh at defuze.org
Wed Dec 20 22:14:23 CET 2006


Sylvain Hellegouarch wrote:
>>> Well, we're using wsgiref's simple_server which only speaks HTTP/1.0,
>>> but we really need to speak HTTP/1.1 and use chunked. Where do you
>>> recommend we put the chunking instead?
> 
> <shameless-plug>
> If you are not to fuss about which WSGI server you can afford to use,
> you could grab the server from CherryPy 3.0 which is HTTP/1.1 fluent.
> 
> from cherrypy import wsgiref [1]
> 
> You'd be done.
> </shameless-plug>

Because an example is worth all the words:

from cherrypy import wsgiserver

def my_crazy_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type','text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']

# This won't call CherryPy machinery at all
# Only the WSGI server which is independant from CherryPy itself
# Its name simply reflects its origin...

server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), [('/',
my_crazy_app)], numthreads=10, server_name='localhost')

# Want SSl support? Just set those attributes
# server.ssl_certificate = ...
# server.ssl_private_key = ...

if __name__ == '__main__':
    server.start()

The nice thing is that you can also support many WSGI applications in
one instance of your server. Anyway only for those who'd be interested ;)


More information about the Web-SIG mailing list