Commit 948d3f16 authored by Vincent Pelletier's avatar Vincent Pelletier

http: Add support for Expect:100-continue request header.

parent acc11f04
......@@ -72,9 +72,24 @@ class ChunkedFile(ProxyFile):
self._recv_buf = result[length:]
return result[:length]
class HookFirstReadFile(ProxyFile):
"""
Trigger a callable on first read.
"""
def __init__(self, actual_file, on_first_read):
super(HookFirstReadFile, self).__init__(actual_file)
self._on_first_read = on_first_read
self.read = self._read_hook
def _read_hook(self, *args, **kw):
self._on_first_read()
del self.read
return self.read(*args, **kw)
class CleanServerHandler(ServerHandler):
"""
- Handle chunked transfer encoding.
- Handle expect/continue protocol.
- Do not include OS environment variables in each request's WSGI environment.
Seriously, what the fsck, python ?
"""
......@@ -97,3 +112,19 @@ class CleanServerHandler(ServerHandler):
# We handle this, hide it from Application
del environ['HTTP_TRANSFER_ENCODING']
environ['wsgi.input'] = ChunkedFile(environ['wsgi.input'])
if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
# We handle this, hide it from Application
del environ['HTTP_EXPECT']
environ['wsgi.input'] = HookFirstReadFile(
environ['wsgi.input'],
self._100_continue,
)
def _100_continue(self):
"""
Emit "100 Continue" intermediate response.
"""
self._write('HTTP/%s 100 Continue\r\n\r\n' % (
self.http_version,
))
self._flush()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment