Skip to content

Commit

Permalink
100-continue patch and reduce memory usage when big uploads aren't read
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Barton committed Jan 5, 2010
1 parent bee6ec4 commit 5b5afd1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions eventlet/wsgi.py
Expand Up @@ -295,8 +295,10 @@ def start_response(status, response_headers, exc_info=None):
if hasattr(result, 'close'):
result.close()
if self.environ['eventlet.input'].position < self.environ.get('CONTENT_LENGTH', 0):
## Read and discard body
self.environ['eventlet.input'].read()
## Read and discard body if there was no pending 100-continue
if not self.environ['eventlet.input'].wfile:
while self.environ['eventlet.input'].read(MINIMUM_CHUNK_SIZE):
pass
finish = time.time()

self.server.log_message('%s - - [%s] "%s" %s %s %.6f' % (
Expand Down
24 changes: 24 additions & 0 deletions tests/wsgi_test.py
Expand Up @@ -529,6 +529,30 @@ def test_023_bad_content_length(self):
self.assert_('400 Bad Request' in result)
self.assert_('500' not in result)

def test_024_expect_100_continue(self):
def wsgi_app(environ, start_response):
if int(environ['CONTENT_LENGTH']) > 1024:
start_response('417 Expectation Failed', [('Content-Length', '7')])
return ['failure']
else:
text = environ['wsgi.input'].read()
start_response('200 OK', [('Content-Length', str(len(text)))])
return [text]
self.site.application = wsgi_app
sock = api.connect_tcp(('localhost', self.port))
fd = sock.makeGreenFile()
fd.write('PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\nExpect: 100-continue\r\n\r\n')
result = fd.readuntil('\r\n\r\n')
self.assert_(result.startswith('HTTP/1.1 417 Expectation Failed'))
self.assertEquals(fd.read(7), 'failure')
fd.write('PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 7\r\nExpect: 100-continue\r\n\r\ntesting')
result = fd.readuntil('\r\n\r\n')
self.assert_(result.startswith('HTTP/1.1 100 Continue'))
result = fd.readuntil('\r\n\r\n')
self.assert_(result.startswith('HTTP/1.1 200 OK'))
self.assertEquals(fd.read(7), 'testing')
fd.close()


if __name__ == '__main__':
main()

0 comments on commit 5b5afd1

Please sign in to comment.