diff --git a/project/tests/test_multipart_forms.py b/project/tests/test_multipart_forms.py new file mode 100644 index 00000000..760ae3cf --- /dev/null +++ b/project/tests/test_multipart_forms.py @@ -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() diff --git a/silk/model_factory.py b/silk/model_factory.py index e80b9e63..ba21fed1 100644 --- a/silk/model_factory.py +++ b/silk/model_factory.py @@ -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'] @@ -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: