Re: [Django] #34989: Set Content-Length where possible for HttpResponses.

4 views
Skip to first unread message

Django

unread,
Dec 20, 2023, 1:25:17 PM12/20/23
to django-...@googlegroups.com
#34989: Set Content-Length where possible for HttpResponses.
-------------------------------------+-------------------------------------
Reporter: Jeppe Fihl-Pearson | Owner: Anders
Type: | Kaseorg
Cleanup/optimization | Status: new
Component: HTTP handling | Version: 4.2
Severity: Normal | Resolution:
Keywords: CommonMiddleware | Triage Stage: Accepted
uWSGI |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Florian Apolloner):

I have been digging a bit more in the RFC and I think setting the
`Content-Length` to `0` is actually preferred since it indicates that
there is really no content (which a redirect is allowed to have).

See https://www.rfc-editor.org/rfc/rfc9110#field.content-length:
> Aside from the cases defined above, in the absence of Transfer-Encoding,
an origin server SHOULD send a Content-Length header field when the
content size is known prior to sending the complete header section. This
will allow downstream recipients to measure transfer progress, know when a
received message is complete, and potentially reuse the connection for
additional requests.

--
Ticket URL: <https://code.djangoproject.com/ticket/34989#comment:13>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 1, 2025, 3:42:21 PM (6 days ago) Sep 1
to django-...@googlegroups.com
#34989: Set Content-Length where possible for HttpResponses.
-------------------------------------+-------------------------------------
Reporter: Jeppe Fihl-Pearson | Owner: Ronan LE
Type: | HAY
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: 4.2
Severity: Normal | Resolution:
Keywords: CommonMiddleware | Triage Stage: Accepted
uWSGI |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ronan LE HAY):

* has_patch: 0 => 1
* owner: Anders Kaseorg => Ronan LE HAY
* status: new => assigned

Comment:

Hello!

I also encountered problems due to the absence of the `Content-Length`
header during a redirect with APPEND_SLASH and after some research I came
across this issue.
The latest comments on this issue seem to be in favor of modifying the
code to add this header, so since the issue hasn't changed for many months
now, I'm proposing this [https://github.com/django/django/pull/19805 PR].
Thank you in advance for your feedback.
--
Ticket URL: <https://code.djangoproject.com/ticket/34989#comment:14>

Django

unread,
Sep 3, 2025, 5:39:10 PM (4 days ago) Sep 3
to django-...@googlegroups.com
#34989: Set Content-Length where possible for HttpResponses.
-------------------------------------+-------------------------------------
Reporter: Jeppe Fihl-Pearson | Owner: Ronan LE
Type: | HAY
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: 4.2
Severity: Normal | Resolution:
Keywords: CommonMiddleware | Triage Stage: Accepted
uWSGI |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e197953f11a7726746bd7c80664cc38d5ea85588" e197953f]:
{{{#!CommitTicketReference repository=""
revision="e197953f11a7726746bd7c80664cc38d5ea85588"
Refs #34989 -- Ensured the Content-Length header is set when redirect with
APPEND_SLASH.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34989#comment:15>
Reply all
Reply to author
Forward
0 new messages