Skip to content

Commit

Permalink
itools: update http
Browse files Browse the repository at this point in the history
  • Loading branch information
David Versmisse authored and J. David Ibanez committed Jul 6, 2010
1 parent 8b68fe6 commit bfc5dbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion itools/examples/http/ping.py
Expand Up @@ -16,13 +16,21 @@

# Import from itools
from itools.http import HTTPServer
from itools.loop import Loop

class Ping(HTTPServer):
def listen(self, address, port):
super(Ping, self).listen(address, port)
self.add_handler('/', self.path_callback)

def path_callback(self, soup_message, path):
method = soup_message.get_method()
body = '%s %s' % (method, path)
soup_message.set_status(200)
soup_message.set_response('text/plain', body)

server = Ping()
server.start()
server.listen('localhost', 8080)

loop = Loop()
loop.run()
12 changes: 9 additions & 3 deletions itools/http.rst
Expand Up @@ -11,8 +11,7 @@

The :mod:`itools.http` package offers an HTTP server with a simple programming
interface. It builds on the HTTP server provided by the `libsoup
<http://live.gnome.org/LibSoup>`_ C library (which is wrapped by the
:mod:`itools.soup` package).
<http://live.gnome.org/LibSoup>`_ C library.

.. note::

Expand All @@ -24,14 +23,21 @@ Example:
.. code-block:: python
from itools.http import HTTPServer
from itools.loop import Loop
class Ping(HTTPServer):
def listen(self, address, port):
super(Ping, self).listen(address, port)
self.add_handler('/', self.path_callback)
def path_callback(self, soup_message, path):
method = soup_message.get_method()
body = '%s %s' % (method, path)
soup_message.set_status(200)
soup_message.set_response('text/plain', body)
server = Ping()
server.start()
server.listen('localhost', 8080)
loop = Loop()
loop.run()

0 comments on commit bfc5dbf

Please sign in to comment.