Skip to content

Commit

Permalink
Edits
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Sep 17, 2019
1 parent 22ec83d commit 06c191b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Full release notes, with more details and upgrade information, are available at:
https://channels.readthedocs.io/en/latest/releases

UNRELEASED
----------

* Adjusted HTTP body handling to use a spooled file, rather than reading
request body into memory. ``AsgiRequest.__init__()`` is adjusted to expected
an IO stream, rather than bytes.

2.2.0 (2019-04-14)
------------------

Expand Down
2 changes: 0 additions & 2 deletions channels/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def _get_scheme(self):

def _get_post(self):
if not hasattr(self, "_post"):
self._read_started = False
self._load_post_and_files()
return self._post

Expand All @@ -140,7 +139,6 @@ def _set_post(self, post):

def _get_files(self):
if not hasattr(self, "_files"):
self._read_started = False
self._load_post_and_files()
return self._files

Expand Down
21 changes: 20 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from django.core.exceptions import RequestDataTooBig
from django.http import HttpResponse
from django.http import HttpResponse, RawPostDataException
from django.test import override_settings

from asgiref.testing import ApplicationCommunicator
Expand Down Expand Up @@ -170,6 +170,25 @@ def test_script_name(self):

self.assertEqual(request.path, "/path/to/test/")

def test_reading_body_after_stream_raises(self):
request = AsgiRequest(
{
"http_version": "1.1",
"method": "POST",
"path": "/test2/",
"query_string": "django=great",
"headers": {
"host": b"example.com",
"content-type": b"application/x-www-form-urlencoded",
"content-length": b"18",
},
},
BytesIO(b"djangoponies=are+awesome"),
)
self.assertEqual(request.read(3), b"dja")
with pytest.raises(RawPostDataException):
request.body

def test_size_exceeded(self):
with override_settings(DATA_UPLOAD_MAX_MEMORY_SIZE=1):
with pytest.raises(RequestDataTooBig):
Expand Down

0 comments on commit 06c191b

Please sign in to comment.