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

Update reference to headers in the response. #127

Closed
wants to merge 1 commit into from
Closed

Update reference to headers in the response. #127

wants to merge 1 commit into from

Conversation

litghost
Copy link

Proposed fix for #126

Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
@coveralls
Copy link

Coverage Status

Coverage decreased (-20.6%) to 79.357% when pulling d627709 on Muon-Space:fix_headers_reference into db7031b on TracyWebTech:master.

Copy link
Member

@thatsed thatsed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I came across the issue updating to Django 3.2. It is related (see this comment on the issue) to an upgrade to the HttpResponse headers interface, so changing the logging entries might get rid of the surface problem but won't actually update the library to full 3.2 compatibility. I left some notes in the review, and I'm making my own fork to further investigate the issue. I'll keep you updated!

@@ -124,7 +124,7 @@ def set_response_headers(response, response_headers):

response[header.title()] = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response headers interface got changed in Django 3.2, see this comment on the related issue.

Django ticket: #31789
Related Django Commit: bcc2befd

To make it compatible:
response.headers[header.title()] = value

@@ -45,7 +45,7 @@ def get_django_response(proxy_response, strict_cookies=False):
logger.info('Normalizing response headers')
set_response_headers(response, headers)

logger.debug('Response headers: %s', getattr(response, '_headers'))
Copy link
Member

@thatsed thatsed Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers is now a public attribute (see comment above). We can ditch the getattr and just use response.headers

@@ -124,7 +124,7 @@ def set_response_headers(response, response_headers):

response[header.title()] = value

logger.debug('Response headers: %s', getattr(response, '_headers'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, ditch the getattr

@thatsed
Copy link
Member

thatsed commented Apr 19, 2021

Also, these changes would make the library incompatible with previous versions of Django (<3.2), so some checks should be in place for that (that is why tests are failing after all).

My proposal is a check for the headers attribute on the response object: if missing, use old strategy; otherwise, use the 3.2 compatible one. A check on the Django version or the django.http.response.ResponseHeaders interface existence (by try import) are also viable options.

@leandrodesouzadev
Copy link

Is there any updates on this issue/pr?
I'm facing the same issue on Django 4.

@sumit4613
Copy link
Member

This issue is already fixed and merged via #137. Closing this MR.

@sumit4613 sumit4613 closed this Dec 21, 2022
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

Successfully merging this pull request may close these issues.

None yet

5 participants