Skip to content

Commit

Permalink
Python 3: Fix Content-Length header in slice().
Browse files Browse the repository at this point in the history
This prevents a http.client.IncompleteRead error in the test.
  • Loading branch information
Ms2ger committed Oct 4, 2018
1 parent 572fdb9 commit 685c505
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions tools/wptserve/tests/functional/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,14 @@ def handler(request, response):
self.assertFalse(resp.info().get("X-TEST"))
self.assertEqual(resp.read(), b"CONTENT")

@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_with_json_handler(self):
@wptserve.handlers.json_handler
def handler(request, response):
return json.dumps({'data': 'PASS'})
route = ("GET", "/test/test_pipes_2/", handler)
self.server.router.register(*route)
resp = self.request(route[1], query="pipe=slice(null,2)")
self.assertEqual(resp.read(), '"{')
self.assertEqual(resp.read(), b'"{')

def test_slice_with_as_is_handler(self):
resp = self.request("/test.asis", query="pipe=slice(null,2)")
Expand Down
5 changes: 3 additions & 2 deletions tools/wptserve/wptserve/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ def slice(request, response, start, end=None):
(spelled "null" in a query string) to indicate the end of
the file.
"""
content = resolve_content(response)
response.content = content[start:end]
content = resolve_content(response)[start:end]
response.content = content
response.headers.set("Content-Length", len(content))
return response


Expand Down

0 comments on commit 685c505

Please sign in to comment.