Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original response is lost when redirection is intercepted #1679

Open
interDist opened this issue Sep 26, 2022 · 5 comments
Open

Original response is lost when redirection is intercepted #1679

interDist opened this issue Sep 26, 2022 · 5 comments

Comments

@interDist
Copy link

The RedirectsPanel creates a new response, preserving only the cookies of the original response. Then any additional information in the original response is lost and cannot be made visible in the toolbar’s panels. In our case, each response has authorization information and I would like to be able to verify that this information is captured correctly also when the user is ultimately redirected. The fix looks quite straightforward, within the if:
https://github.com/jazzband/django-debug-toolbar/blob/f1387801e84a343fbce5c7955423f87589790a26/debug_toolbar/panels/redirects.py#L20
modify the code creating the new response to

    original_response = response
    response = SimpleTemplateResponse( ... )
    response.original_response = original_response

Everything else will be taken care of by custom code in the relevant panels...

@tim-schilling
Copy link
Member

@interDist sorry I never responded to this. Do you remember why this worked for you? I don't see original_response used anywhere, so I'm not sure how that helps you.

@interDist
Copy link
Author

I had to remember what this is about and my idea for a solution, this was one year ago... 😏
Basically we have custom panels or customizations of the existing panels, that would need the extra information from the original response. My idea was that this custom code would do getattr(response, 'original_response', response).extra_data. I have not included this code in the end, because I didn’t want to reimplement the RedirectsPanel. So at this moment we cannot inspect this extra information via the Debug Toolbar when the request is redirected.

@tim-schilling
Copy link
Member

Understood. Unless we use that original response somewhere, I'm inclined to not collect it in the first place. If someone does need it, it's relatively straightforward to subclass RedirectsPanel and capture it.

@interDist
Copy link
Author

Would it be possible then to add a callback point which subclasses can use? It would be called after the new response is created and before it is rendered, with both the original response and the redirect capture response.

@tim-schilling
Copy link
Member

I think I'd be on board with a PR that changes RedirectsPanels to use a new method called def get_interception_response(self, response) -> SimpleTemplateResponse or something similar.

From what I understand that should provide you with the hook to do what you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants