#20459 closed Cleanup/optimization (fixed)

Better example for setting header fields in documentation

Reported by: bbjay Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: bbjay Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I think the current example for setting header fields in HttpResponse objects is a bit unfortunate:
https://docs.djangoproject.com/en/dev/ref/request-response/#setting-header-fields

The Cache-Control field (also the Vary field) is a comma-separated multi value field.
e.g. Cache-Control: public, max-age=60
Setting its value by a dictionary access can unintentionally remove other present values, e.g. set by another middleware.

My proposed solution: change example to use 'Age' header field, mention and encourage use of patch_vary_header and patch_cache_control methods.
https://github.com/bbjay/django/commit/227f4bf4fe7971754ecc09aeb141b824a3f0550b

Change History (5)

comment:1 Changed 22 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 22 months ago by tadeck

That fix looks nice. Would you care to create pull request etc., or should someone else do that?

comment:3 Changed 22 months ago by bbjay

Cool. Yes, i will gladly do that, just wanted to hear another opinion before filling a PR.
btw: do i need to set myself to cc to get updates for this ticket by email?

comment:4 Changed 22 months ago by bbjay

  • Cc bbjay added
  • Has patch set

comment:5 Changed 22 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In e83ff42792eb52235cacda58f3441673cc4e4c94:

Fixed #20459 - Improved example for setting HTTP header fields.

Thanks Jérémie Blaser.

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