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

Setting custom headers on initial WebSocket HTTP Upgrade response #204

Open
2 tasks done
bahamut657 opened this issue May 24, 2022 · 2 comments
Open
2 tasks done

Comments

@bahamut657
Copy link

bahamut657 commented May 24, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I'm building an HTTP reverse proxy using fastify.
In order to support other 3rd parts WebSocket connections, proxied by my software, I need a way to rewrite headers obtained in UPGRADE response from the replicated WS connection.
Is there a way to write some custom header in the initial upgrade request?

Example

In my case I have to replicate this headers:

Connection: upgrade
Content-Type: application/octet-stream
Date: Tue, 24 May 2022 16:19:40 GMT
Sec-WebSocket-Accept: MGhCOJFY8ayJUf3cJ+BcSgTwOOg=
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Protocol: tty
Server: Python/3.9 aiohttp/3.8.1
Upgrade: websocket

But from the reverse proxy I obtain this response:

Connection: Upgrade
Sec-WebSocket-Accept: 0hWXq3owSgRUjfyWd9dJpW6+lm0=
Sec-WebSocket-Protocol: tty
Upgrade: websocket

I have some missing fields and one to rewrite

@airhorns
Copy link
Member

I don't think we support this right now and I took a quick look and it's not immediately obvious to me how we might add support. Its a bit tricky to write HTTP headers at the right moment before the connection becomes a bidirectional socket, but, it is definitely technically possible. Want to try a PR?

@bahamut657
Copy link
Author

bahamut657 commented May 24, 2022

Sure, I can try a PR.
Could you suggest me the right starting point (files/mechanisms) to look at?

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