mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #32162 -- Fixed setting Content-Length header in AsyncRequestFactory.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							b03b19b585
						
					
				
				
					commit
					542b4b3ab4
				
			| @@ -540,7 +540,7 @@ class AsyncRequestFactory(RequestFactory): | ||||
|         } | ||||
|         if data: | ||||
|             s['headers'].extend([ | ||||
|                 (b'content-length', bytes(len(data))), | ||||
|                 (b'content-length', str(len(data)).encode('ascii')), | ||||
|                 (b'content-type', content_type.encode('ascii')), | ||||
|             ]) | ||||
|             s['_body_file'] = FakePayload(data) | ||||
|   | ||||
| @@ -9,4 +9,5 @@ Django 3.1.4 fixes several bugs in 3.1.3. | ||||
| Bugfixes | ||||
| ======== | ||||
|  | ||||
| * ... | ||||
| * Fixed setting the ``Content-Length`` HTTP header in ``AsyncRequestFactory`` | ||||
|   (:ticket:`32162`). | ||||
|   | ||||
| @@ -997,3 +997,18 @@ class AsyncRequestFactoryTest(SimpleTestCase): | ||||
|                 request = method('/somewhere/') | ||||
|                 response = await async_generic_view(request) | ||||
|                 self.assertEqual(response.status_code, 200) | ||||
|  | ||||
|     async def test_request_factory_data(self): | ||||
|         async def async_generic_view(request): | ||||
|             return HttpResponse(status=200, content=request.body) | ||||
|  | ||||
|         request = self.request_factory.post( | ||||
|             '/somewhere/', | ||||
|             data={'example': 'data'}, | ||||
|             content_type='application/json', | ||||
|         ) | ||||
|         self.assertEqual(request.headers['content-length'], '19') | ||||
|         self.assertEqual(request.headers['content-type'], 'application/json') | ||||
|         response = await async_generic_view(request) | ||||
|         self.assertEqual(response.status_code, 200) | ||||
|         self.assertEqual(response.content, b'{"example": "data"}') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user