Skip to content

Commit

Permalink
Set the non-standard wsgi.input_terminated flag. Fixes gevent#1308.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden authored and Ricardo Kirkner committed Nov 30, 2018
1 parent c8e16bc commit 4beac0c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -50,6 +50,9 @@
enums instead of plain integers for the socket type and address
family on Python 3. See :issue:`1310` reported by TheYOSH.

- Make gevent's pywsgi server set the non-standard environment value
``wsgi.input_terminated`` to True. See :issue:`1308`.

1.3.7 (2018-10-12)
==================

Expand Down
4 changes: 4 additions & 0 deletions src/gevent/pywsgi.py
Expand Up @@ -1119,6 +1119,10 @@ def get_environ(self):
chunked = env.get('HTTP_TRANSFER_ENCODING', '').lower() == 'chunked'
self.wsgi_input = Input(self.rfile, self.content_length, socket=sock, chunked_input=chunked)
env['wsgi.input'] = self.wsgi_input
# This is a non-standard flag indicating that our input stream is
# self-terminated (returns EOF when consumed).
# See https://github.com/gevent/gevent/issues/1308
env['wsgi.input_terminated'] = True
return env


Expand Down
19 changes: 11 additions & 8 deletions src/gevent/tests/test__pywsgi.py
Expand Up @@ -371,8 +371,8 @@ class TestNoChunks(CommonTests):
# it calculates the content-length and joins all the chunks before sending
validator = None

@staticmethod
def application(env, start_response):
def application(self, env, start_response):
self.assertTrue(env.get('wsgi.input_terminated'))
path = env['PATH_INFO']
if path == '/':
start_response('200 OK', [('Content-Type', 'text/plain')])
Expand Down Expand Up @@ -400,8 +400,8 @@ class TestExplicitContentLength(TestNoChunks): # pylint:disable=too-many-ancesto
# when returning a list of strings a shortcut is empoyed by the
# server - it caculates the content-length

@staticmethod
def application(env, start_response):
def application(self, env, start_response):
self.assertTrue(env.get('wsgi.input_terminated'))
path = env['PATH_INFO']
if path == '/':
start_response('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', '11')])
Expand Down Expand Up @@ -520,6 +520,7 @@ def body(self):
return b''.join(self.chunks)

def application(self, env, start_response):
self.assertTrue(env.get('wsgi.input_terminated'))
start_response('200 OK', [('Content-Type', 'text/plain')])
for chunk in self.chunks:
yield chunk
Expand Down Expand Up @@ -552,8 +553,9 @@ class TestBigChunks(TestChunkedApp):


class TestNegativeRead(TestCase):
@staticmethod
def application(env, start_response):

def application(self, env, start_response):
self.assertTrue(env.get('wsgi.input_terminated'))
start_response('200 OK', [('Content-Type', 'text/plain')])
if env['PATH_INFO'] == '/read':
data = env['wsgi.input'].read(-1)
Expand Down Expand Up @@ -605,8 +607,9 @@ def test_negative_nonchunked_readline(self):

class TestChunkedPost(TestCase):

@staticmethod
def application(env, start_response):

def application(self, env, start_response):
self.assertTrue(env.get('wsgi.input_terminated'))
start_response('200 OK', [('Content-Type', 'text/plain')])
if env['PATH_INFO'] == '/a':
data = env['wsgi.input'].read(6)
Expand Down
5 changes: 3 additions & 2 deletions src/gevent/tests/test__socket_dns.py
Expand Up @@ -412,7 +412,8 @@ class Test1234(TestCase):
class Test127001(TestCase):
pass

add(Test127001, '127.0.0.1',
add(
Test127001, '127.0.0.1',
skip=greentest.RUNNING_ON_TRAVIS,
skip_reason="Beginning Dec 1 2017, ares started returning ip6-localhost "
"instead of localhost"
Expand Down Expand Up @@ -621,7 +622,7 @@ def cleanup(self):
# gaierror: [Errno -2] Name or service not known
try:
gevent.get_hub().threadpool.join()
except Exception: # pylint:disable=broad-except pragma: no cover
except Exception: # pragma: no cover pylint:disable=broad-except
traceback.print_exc()


Expand Down

0 comments on commit 4beac0c

Please sign in to comment.