| 1 | | |
|---|
| 2 | | ######################################################################### |
|---|
| 3 | | # |
|---|
| 4 | | # # Simplest example on how to use this module directly |
|---|
| 5 | | # # Without going through the CherryPy machinery |
|---|
| 6 | | # |
|---|
| 7 | | # from cherrypy import wsgiserver |
|---|
| 8 | | # |
|---|
| 9 | | # def my_crazy_app(environ, start_response): |
|---|
| 10 | | # status = '200 OK' |
|---|
| 11 | | # response_headers = [('Content-type','text/plain')] |
|---|
| 12 | | # start_response(status, response_headers) |
|---|
| 13 | | # return ['Hello world!\n'] |
|---|
| 14 | | # |
|---|
| 15 | | # # The CherryPy WSGI server can serve as many WSGI application |
|---|
| 16 | | # # as you want in one instance |
|---|
| 17 | | # |
|---|
| 18 | | # # Her we set our application to the script_name '/' |
|---|
| 19 | | # wsgi_apps = [('/', my_crazy_app)] |
|---|
| 20 | | # |
|---|
| 21 | | # # This won't call CherryPy machinery at all |
|---|
| 22 | | # # Only the WSGI server which is independant from CherryPy itself |
|---|
| 23 | | # # Its name reflects its origin... |
|---|
| 24 | | # server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), |
|---|
| 25 | | # wsgi_apps, server_name='localhost') |
|---|
| 26 | | # |
|---|
| 27 | | # # Want SSL support? Just set those attributes |
|---|
| 28 | | # # server.ssl_certificate = ... |
|---|
| 29 | | # # server.ssl_private_key = ... |
|---|
| 30 | | # |
|---|
| 31 | | # if __name__ == '__main__': |
|---|
| 32 | | # server.start() |
|---|
| 33 | | ######################################################################### |
|---|
| 34 | | |
|---|
| 35 | | """A high-speed, production ready, thread pooled, generic WSGI server.""" |
|---|
| | 1 | """A high-speed, production ready, thread pooled, generic WSGI server. |
|---|
| | 2 | |
|---|
| | 3 | Simplest example on how to use this module directly |
|---|
| | 4 | (without using CherryPy's application machinery): |
|---|
| | 5 | |
|---|
| | 6 | from cherrypy import wsgiserver |
|---|
| | 7 | |
|---|
| | 8 | def my_crazy_app(environ, start_response): |
|---|
| | 9 | status = '200 OK' |
|---|
| | 10 | response_headers = [('Content-type','text/plain')] |
|---|
| | 11 | start_response(status, response_headers) |
|---|
| | 12 | return ['Hello world!\n'] |
|---|
| | 13 | |
|---|
| | 14 | # Here we set our application to the script_name '/' |
|---|
| | 15 | wsgi_apps = [('/', my_crazy_app)] |
|---|
| | 16 | |
|---|
| | 17 | server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), wsgi_apps, |
|---|
| | 18 | server_name='localhost') |
|---|
| | 19 | |
|---|
| | 20 | # Want SSL support? Just set these attributes |
|---|
| | 21 | # server.ssl_certificate = <filename> |
|---|
| | 22 | # server.ssl_private_key = <filename> |
|---|
| | 23 | |
|---|
| | 24 | if __name__ == '__main__': |
|---|
| | 25 | server.start() |
|---|
| | 26 | |
|---|
| | 27 | This won't call the CherryPy engine (application side) at all, only the |
|---|
| | 28 | WSGI server, which is independant from the rest of CherryPy. Don't |
|---|
| | 29 | let the name "CherryPyWSGIServer" throw you; the name merely reflects |
|---|
| | 30 | its origin, not it's coupling. |
|---|
| | 31 | |
|---|
| | 32 | The CherryPy WSGI server can serve as many WSGI application |
|---|
| | 33 | as you want in one instance: |
|---|
| | 34 | |
|---|
| | 35 | wsgi_apps = [('/', my_crazy_app), (/blog', my_blog_app)] |
|---|
| | 36 | |
|---|
| | 37 | """ |
|---|
| | 38 | |
|---|
| 86 | | |
|---|
| 87 | | |
|---|
| | 89 | """An HTTP Request (and response). |
|---|
| | 90 | |
|---|
| | 91 | A single HTTP connection may consist of multiple request/response pairs. |
|---|
| | 92 | |
|---|
| | 93 | connection: the HTTP Connection object which spawned this request. |
|---|
| | 94 | rfile: the 'read' fileobject from the connection's socket |
|---|
| | 95 | ready: when True, the request has been parsed and is ready to begin |
|---|
| | 96 | generating the response. When False, signals the calling Connection |
|---|
| | 97 | that the response should not be generated and the connection should |
|---|
| | 98 | close. |
|---|
| | 99 | close_connection: signals the calling Connection that the request |
|---|
| | 100 | should close. This does not imply an error! The client and/or |
|---|
| | 101 | server may each request that the connection be closed. |
|---|
| | 102 | chunked_write: if True, output will be encoded with the "chunked" |
|---|
| | 103 | transfer-coding. This value is set automatically inside |
|---|
| | 104 | send_headers. |
|---|
| | 105 | """ |
|---|
| | 106 | |
|---|
| | 505 | """An HTTP connection (active socket). |
|---|
| | 506 | |
|---|
| | 507 | socket: the raw socket object (usually TCP) for this connection. |
|---|
| | 508 | addr: the "bind address" for the remote end of the socket. |
|---|
| | 509 | For IP sockets, this is a tuple of (REMOTE_ADDR, REMOTE_PORT). |
|---|
| | 510 | For UNIX domain sockets, this will be a string. |
|---|
| | 511 | server: the HTTP Server for this Connection. Usually, the server |
|---|
| | 512 | object possesses a passive (server) socket which spawns multiple, |
|---|
| | 513 | active (client) sockets, one for each connection. |
|---|
| | 514 | |
|---|
| | 515 | environ: a WSGI environ template. This will be copied for each request. |
|---|
| | 516 | rfile: a fileobject for reading from the socket. |
|---|
| | 517 | wfile: a fileobject for writing to the socket. |
|---|
| | 518 | """ |
|---|
| | 689 | |
|---|
| | 690 | protocol: the version string to write in the Status-Line of all |
|---|
| | 691 | HTTP responses. For example, "HTTP/1.1" (the default). This |
|---|
| | 692 | also limits the supported features used in the response. |
|---|
| | 693 | |
|---|
| | 694 | |
|---|
| | 695 | SSL/HTTPS |
|---|
| | 696 | --------- |
|---|
| | 697 | The OpenSSL module must be importable for SSL functionality. |
|---|
| | 698 | You can obtain it from http://pyopenssl.sourceforge.net/ |
|---|
| | 699 | |
|---|
| | 700 | ssl_certificate: the filename of the server SSL certificate. |
|---|
| | 701 | ssl_privatekey: the filename of the server's private key file. |
|---|
| | 702 | |
|---|
| | 703 | If either of these is None (both are None by default), this server |
|---|
| | 704 | will not use SSL. If both are given and are valid, they will be read |
|---|
| | 705 | on server start and used in the SSL context for the listening socket. |
|---|