Skip to content
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ answer newbie questions, and generally made Django that much better:
Roel Delos Reyes <https://roelzkie.dev>
Rohith P R <https://rohithpr.com>
Romain Garrigues <romain.garrigues.cs@gmail.com>
Ronan LE HAY <ronan@le-hay.fr>
Ronnie van den Crommenacker
Ronny Haryanto <https://ronny.haryan.to/>
Ross Poulton <ross@rossp.org>
Expand Down
4 changes: 3 additions & 1 deletion django/middleware/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def process_response(self, request, response):
# If the given URL is "Not Found", then check if we should redirect to
# a path with a slash appended.
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
# already set.
Expand Down
13 changes: 13 additions & 0 deletions tests/middleware/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ def get_response(req):
response = CommonMiddleware(get_response)(self.rf.get("/"))
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

@override_settings(DISALLOWED_USER_AGENTS=[re.compile(r"foo")])
Expand Down
Loading