Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:40:00+00:00 2026-06-14T03:40:00+00:00

I have a reasonably large project in Django, which is a reasonably large framework,

  • 0

I have a reasonably large project in Django, which is a reasonably large framework, and I’m using a reasonably large number of apps, middlewares, context processors, etc. The scale means that when a part of the codebase runs for requests where I don’t want it to, identifying why it did is hard. Straight code inspection is much too time-consuming, as is single-stepping through the entire request in a debugger.

In this particular case, my problem is that I’m getting “Vary: Cookie” set on every response, including some that I want heavily cached and where I shouldn’t need any cookies. I suspect, but don’t know how to prove, that some middleware or context processor is accessing request.session even when it doesn’t use the result–though it might be an indirect access, such as through request.user. And of course it might be something else entirely.

In Python, how would you trace from an effect (“the Vary header was added to the response”) back to its cause in a large codebase?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:40:01+00:00Added an answer on June 14, 2026 at 3:40 am

    Here’s a thought: monkey patch the django HttpResponse class so that its __setitem__ method raises an exception if the header being set is Vary. You can take care of this from an otherwise do-nothing middleware when it’s created. It should give you a nice traceback from the line that’s setting the header.

    class MonkeyPatchMiddleware(object):
    
       def __init__(self):
           from django.http import HttpResponse
    
           original_set_item = HttpResponse.__setitem__
    
           def __setitem__(self, header, value):
               if header == "Vary":
                   raise ValueError
               original_set_item(self, header, value)
    
           HttpResponse.__setitem__ = __setitem__
    

    Install the middleware as the first thing in your middleware stack in your django settings file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reasonably large (thousands of files) project which is divided between client
I can't sleep! :) I have a reasonably large project on Windows and encountered
I have a fairly large (new) project in which we have annotated many domain
Hey Folks. I have a reasonably large commercial project (so for-pay licensing is always
I have a reasonably large project at work that I've inherited. It's an ASP.NET
I've written 2 reasonably large scale apps in .net so far, and both of
I'm using an Entity Framework project in which I need to batch update records
I have two test cases using a reasonably large json object (1.2mb): source: data
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
I have some data which (quite reasonably) uses null and false for different meanings.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.