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

feat: take client request headers into account when deciding whether to reuse WS conns #647

Merged

Conversation

fiam
Copy link
Contributor

@fiam fiam commented Oct 27, 2023

Allow callers to indicate a list of headers (by name / regular expression) that must be taken into account when deciding to reuse connections.

…to reuse WS conns

Otherwise it's not possible for the client to route headers through the engine because
a connection with different headers might be reused instead of creating a new one.
Instead, now we only reuse connections if the headers except Sec-Websocket-Key
and Content-Length match.
// However, to improve the changes of connection reuse we do skip
// some headers that are very likely to be different but very unlikely
// to cause different responses, otherwise no connections would be reused.
for key, values := range ctx.Request.Header {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have an allow list of headers that we want to add to the hash.
E.g. in most cases I think we want to limit this to just "Authorization".
This allow list could be configurable at the resolver level, and then we expose it through the cosmo router yaml.
WDYT?

I can also imagine use cases where we want the user to be authenticated, but the origin connection should not use the Authorization header. So the behavior should be configurable and potentially opt-out.

cc @StarpTech

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree, it should be configurable and I like the proposal to maintain a waitlist rather than taking all headers into consideration. I'd definitely add Authorization by default to prevent data exposure and let the rest be use case specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've refactored it so the caller can pass a list of headers. This allows us to make it automatic in the router side, by passing the headers declared in the forwarding rules. PTAL

fiam added 9 commits November 2, 2023 10:10
…d-support-for-forwarding-headers-via-websocket
Introduce a new field in SubscriptionConfiguration that allows selecting which
headers get hashed when decided when to reuse a connection.
…-forwarding-headers-via-websocket' into alberto/eng-4378-add-support-for-forwarding-headers-via-websocket
…d-support-for-forwarding-headers-via-websocket
…d-support-for-forwarding-headers-via-websocket
@fiam fiam merged commit c23f458 into master Nov 6, 2023
6 checks passed
@fiam fiam deleted the alberto/eng-4378-add-support-for-forwarding-headers-via-websocket branch November 6, 2023 12:51
pvormste added a commit to TykTechnologies/graphql-go-tools that referenced this pull request Nov 8, 2023
…to reuse WS conns (wundergraph#647)

Allow callers to indicate a list of headers (by name / regular
expression) that must be taken into account when deciding to reuse
connections.
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.

3 participants