Skip to content

Commit

Permalink
Added example usage of contrib.http.server
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Allik committed Aug 27, 2013
1 parent a72b5ab commit d851ddb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spinoff/examples/005_http.py
@@ -0,0 +1,34 @@
from gevent import sleep

from spinoff.actor import Actor
from spinoff.contrib.http.server import HttpServer


class Main(Actor):
def run(self):
http_srv = self.spawn(HttpServer.using(address=('localhost', 8080), responders=[
(r'^/$', IndexResponder),
(r'^/foo$', FooResponder),
]))
http_srv.join()


class IndexResponder(Actor):
def run(self, request):
request.start_response('200 OK', [('Content-Type', 'text/html')])
request.write('index')
request.close()


class FooResponder(Actor):
def run(self, request):
request.start_response('200 OK', [('Content-Type', 'text/html')])
request.write('foo\n')
self.spawn(SubResponder.using(request))


class SubResponder(Actor):
def run(self, req):
sleep(1.0)
req.write('sub\n')
req.close()

0 comments on commit d851ddb

Please sign in to comment.