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

Fix x_forwarded_proto for websockets in proxy_headers.py #2011

Closed
wants to merge 1 commit into from

Conversation

1997cui
Copy link

@1997cui 1997cui commented Jun 19, 2023

Summary

As discussed in #1933, the upstream proxies (i.e., Caddy) will always pass http or https in x_forwarded_proto, even if it is a WebSocket Upgrade request. However, storing the http or https in a WebSocket scope is not correct. In this pull request, I added some if statements to solve this issue.

I know there are no unit tests, because I don't know how to write, and help wanted.

This PR is based on #1934 based on suggestions from @Kludex and @aminalaee

Checklist

  • [ x ] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [ x ] I've updated the documentation accordingly.

headers[b"x-forwarded-proto"].decode("latin1").strip()
)
if scope["type"] == "websocket":
scope["scheme"] = (
Copy link
Member

Choose a reason for hiding this comment

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

This line is missing a test coverage. Can you please add that?

Copy link
Author

@1997cui 1997cui Jun 22, 2023

Choose a reason for hiding this comment

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

I know there are no unit tests, because I don't know how to write, and help wanted.

Can you give me some examples of how to do a websocket test client? It seems that httpx does not support it. #2012

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

That issue is not related

@Kludex
Copy link
Sponsor Member

Kludex commented Jul 12, 2023

Thanks @1997cui for the interest! :)

@Kludex Kludex closed this Jul 12, 2023
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

3 participants