#36688: GzipMiddleware adds 'Vary: Accept-Encoding' unnecessarily
-------------------------------+----------------------------------------
     Reporter:  Adam Johnson   |                    Owner:  Adam Johnson
         Type:  Bug            |                   Status:  closed
    Component:  HTTP handling  |                  Version:  dev
     Severity:  Normal         |               Resolution:  invalid
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+----------------------------------------
Changes (by Adam Johnson):

 * resolution:   => invalid
 * status:  assigned => closed

Comment:

 Okay, I'm wrong. `Vary: Accept-Encoding` should be sent anyway, because
 the  `Accept-Encoding` header is inspected, regardless of compression
 outcome. I checked this with Claude, by asking its opinion and getting it
 to test the behaviour of nginx and caddy with incompressible random data.
 [https://gist.github.com/adamchainz/17c22f9aa87ce821972186964ce3d310 log
 in this GIST]. (Oddly nginx requires `gzip_vary on` to even set the `Vary`
 header, which seems wrong.)

 But I think something is wrong then that we don't add the `Vary` header
 before the *first* early-return clause:

 {{{#!python
 if not response.streaming and len(response.content) < 200:
     return response
 }}}

 Just because the length was too small doesn't mean we wouldn't compress
 the same URL when it sends larger values, as size may be dynamic. But I
 think this is minor and I will reserve reporting it as a bug for a future
 larger proposal to refactor the whole middleware to support zstd too,
 based on [https://github.com/adamchainz/django-http-compression django-
 http-compression].
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36688#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019a20cc04c1-f223d1a8-81c3-426d-be55-a6ba644f2adf-000000%40eu-central-1.amazonses.com.

Reply via email to