mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #34989 -- Ensured the Content-Length header is set when redirect with APPEND_SLASH.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							d82f25d3f0
						
					
				
				
					commit
					e197953f11
				
			
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -908,6 +908,7 @@ answer newbie questions, and generally made Django that much better: | |||||||
|     Roel Delos Reyes <https://roelzkie.dev> |     Roel Delos Reyes <https://roelzkie.dev> | ||||||
|     Rohith P R <https://rohithpr.com> |     Rohith P R <https://rohithpr.com> | ||||||
|     Romain Garrigues <romain.garrigues.cs@gmail.com> |     Romain Garrigues <romain.garrigues.cs@gmail.com> | ||||||
|  |     Ronan LE HAY <ronan@le-hay.fr> | ||||||
|     Ronnie van den Crommenacker |     Ronnie van den Crommenacker | ||||||
|     Ronny Haryanto <https://ronny.haryan.to/> |     Ronny Haryanto <https://ronny.haryan.to/> | ||||||
|     Ross Poulton <ross@rossp.org> |     Ross Poulton <ross@rossp.org> | ||||||
|   | |||||||
| @@ -105,7 +105,9 @@ class CommonMiddleware(MiddlewareMixin): | |||||||
|         # If the given URL is "Not Found", then check if we should redirect to |         # If the given URL is "Not Found", then check if we should redirect to | ||||||
|         # a path with a slash appended. |         # a path with a slash appended. | ||||||
|         if response.status_code == 404 and self.should_redirect_with_slash(request): |         if response.status_code == 404 and self.should_redirect_with_slash(request): | ||||||
|             return self.response_redirect_class(self.get_full_path_with_slash(request)) |             response = self.response_redirect_class( | ||||||
|  |                 self.get_full_path_with_slash(request) | ||||||
|  |             ) | ||||||
|  |  | ||||||
|         # Add the Content-Length header to non-streaming responses if not |         # Add the Content-Length header to non-streaming responses if not | ||||||
|         # already set. |         # already set. | ||||||
|   | |||||||
| @@ -350,6 +350,19 @@ class CommonMiddlewareTest(SimpleTestCase): | |||||||
|         response = CommonMiddleware(get_response)(self.rf.get("/")) |         response = CommonMiddleware(get_response)(self.rf.get("/")) | ||||||
|         self.assertEqual(int(response.headers["Content-Length"]), bad_content_length) |         self.assertEqual(int(response.headers["Content-Length"]), bad_content_length) | ||||||
|  |  | ||||||
|  |     @override_settings(APPEND_SLASH=True) | ||||||
|  |     def test_content_length_header_added_to_append_slash_redirect(self): | ||||||
|  |         """ | ||||||
|  |         The Content-Length header is set when redirecting with the APPEND_SLASH | ||||||
|  |         setting. | ||||||
|  |         """ | ||||||
|  |         request = self.rf.get("/customurlconf/slash") | ||||||
|  |         request.urlconf = "middleware.extra_urls" | ||||||
|  |         r = CommonMiddleware(get_response_404)(request) | ||||||
|  |         self.assertEqual(r.status_code, 301) | ||||||
|  |         self.assertEqual(r.url, "/customurlconf/slash/") | ||||||
|  |         self.assertTrue(r.has_header("Content-Length")) | ||||||
|  |  | ||||||
|     # Other tests |     # Other tests | ||||||
|  |  | ||||||
|     @override_settings(DISALLOWED_USER_AGENTS=[re.compile(r"foo")]) |     @override_settings(DISALLOWED_USER_AGENTS=[re.compile(r"foo")]) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user