Skip to content

Commit

Permalink
Added Request.set_status in contrib.http
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Allik committed Aug 28, 2013
1 parent 7197ec4 commit fd97b5d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spinoff/contrib/http/server.py
Expand Up @@ -12,14 +12,15 @@


class HttpServer(Actor):
def pre_start(self, address, responders):
def pre_start(self, address, responders, default_content_type='text/html'):
self.responders = responders
self.default_content_type = default_content_type
self.server = WSGIServer(address, self.handle_wsgi_request)
self.server.start()

def handle_wsgi_request(self, env, start_response):
ch = Channel()
req = Request(ch, env, start_response)
req = Request(ch, env, start_response, default_content_type=self.default_content_type)
self << ('handle', req)
return response_stream(ch)

Expand Down Expand Up @@ -88,13 +89,17 @@ def response_stream(ch):


class Request(object):
def __init__(self, ch, env, start_response):
def __init__(self, ch, env, start_response, default_content_type):
self.ch = ch
self.env = env
self._response_started = False
self._start_response = start_response
self.default_content_type = default_content_type
self.closed = False

def set_status(self, status):
self.start_response(status, [('Content-Type', self.default_content_type)])

def start_response(self, *args):
self._response_started = True
ret = self._start_response(*args)
Expand Down

0 comments on commit fd97b5d

Please sign in to comment.