Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28786 closed Cleanup/optimization (fixed)

Document middleware ordering considerations due to CommonMiddleware setting Content-Length

Reported by: spudnica Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal Keywords: content-length, commonMiddleware, development-server
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by spudnica)

Hi!

After updating to Django 1.11 I cant display pages in Chrome, due to error printed in Chrome console: net::ERR_CONTENT_LENGTH_MISMATCH

The above error does not occur in Mozilla or IE. When I delete lines responsible for Content-Length header from CommonMiddleware error disappears and my site works just fine.

Its not just mine Chrome, I tested issue on few PCs.

Change History (9)

comment:1 by spudnica, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

I think we'll need more details about how to reproduce the problem.

in reply to:  2 comment:3 by spudnica, 7 years ago

Description: modified (diff)

Replying to Tim Graham:

I think we'll need more details about how to reproduce the problem.

  1. I guess the issue is related to way that content-length is calculated. If I manually set content-length to match particular page I request for, I am able to open this in Chrome. It seems that str(len(response.content)) is not returning proper reponse length i CommonMiddleware for me and firefox was just ignoring it.
  2. If I order CommonMiddleware at first place in my middlewares list, site is working properly, though it is against reccommendations in Django docs guide Middleware ordering.
  3. If i disable all middlewares that are added to site by myself, and place CommonMiddleware in right order, the error doesnt occur, so its realted to way how the length size calculated.
Last edited 7 years ago by spudnica (previous) (diff)

comment:4 by Tim Graham, 7 years ago

Can you provide a sample project that demonstrates the problem?

comment:5 by spudnica, 7 years ago

Error is related to middleware order. If the content is modified after calculation of length (and in my case it was) comparison between values always returns False. I guess it affects everyone with apps like django-livereload or similar apps, which injects content into site. Is this header necessary to exist because of security or some different point?

Its worth to add info about order of middlewares to release notes of version 1.11, to prevent people from digging through internet.

Last edited 7 years ago by spudnica (previous) (diff)

comment:6 by Tim Graham, 7 years ago

Component: Core (Other)Documentation
Has patch: set
Summary: Content-Length mismatch on ChromeDocument middleware ordering considerations due to CommonMiddleware setting Content-Length
Type: UncategorizedCleanup/optimization

PR to mention that consideration in the release notes.

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:7 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In bc95314c:

Fixed #28786 -- Doc'd middleware ordering considerations due to CommonMiddleware setting Content-Length.

comment:8 by Tim Graham <timograham@…>, 7 years ago

In 3f372ef9:

[2.0.x] Fixed #28786 -- Doc'd middleware ordering considerations due to CommonMiddleware setting Content-Length.

Backport of bc95314ca6af0b5e993ae07fdc7d8e6166d3b8ca from master

comment:9 by Tim Graham <timograham@…>, 7 years ago

In afcde504:

[1.11.x] Fixed #28786 -- Doc'd middleware ordering considerations due to CommonMiddleware setting Content-Length.

Backport of bc95314ca6af0b5e993ae07fdc7d8e6166d3b8ca from master

Note: See TracTickets for help on using tickets.
Back to Top