Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart forms and RawPostDataException #592

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions project/tests/test_multipart_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from unittest.mock import Mock

from django.test import TestCase
from django.urls import reverse

from silk.model_factory import RequestModelFactory, multipart_form


class TestMultipartForms(TestCase):

def test_no_max_request(self):
mock_request = Mock()
mock_request.META = {'CONTENT_TYPE': multipart_form}
mock_request.GET = {}
mock_request.path = reverse('silk:requests')
mock_request.method = 'post'
mock_request.body = Mock()
request_model = RequestModelFactory(mock_request).construct_request_model()
self.assertFalse(request_model.body)
self.assertEqual(b"Raw body not available for multipart_form data, Silk is not showing file uploads.", request_model.raw_body)
mock_request.body.assert_not_called()
7 changes: 6 additions & 1 deletion silk/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'text/javascript',
'text/x-javascript',
'text/x-json']
content_type_form = ['multipart/form-data',
multipart_form = 'multipart/form-data'
content_type_form = [multipart_form,
'application/x-www-form-urlencoded']
content_type_html = ['text/html']
content_type_css = ['text/css']
Expand Down Expand Up @@ -162,6 +163,10 @@ def _body(self, raw_body, content_type):

def body(self):
content_type, char_set = self.content_type()
if content_type == multipart_form:
raw_body = b"Raw body not available for multipart_form data, Silk is not showing file uploads."
body = ''
return body, raw_body
try:
raw_body = self.request.body
except RequestDataTooBig:
Expand Down