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

Add builder for additional header values #400

Merged

Conversation

ManevilleF
Copy link
Contributor

Work done

Added a ClientRequestBuilder type inspired by websockets to allow for additional header values in the request, like authorization or subprotocols.

The way I implemented this is not the cleanest but I wanted to avoid any breaking change.

This is merely a proposal, so feedback welcome !

@Its-Just-Nans
Copy link
Contributor

Its-Just-Nans commented Jan 19, 2024

This would be great to simulate a connection from a browser !

8.   The request MUST include a header field with the name |Origin|
        [[RFC6454](https://datatracker.ietf.org/doc/html/rfc6454)] if the request is coming from a browser client.  If
        the connection is from a non-browser client, the request MAY
        include this header field if the semantics of that client match
        the use-case described here for browser clients.  The value of
        this header field is the ASCII serialization of origin of the
        context in which the code establishing the connection is
        running.  See [[RFC6454](https://datatracker.ietf.org/doc/html/rfc6454)] for the details of how this header field
        value is constructed.

@ManevilleF I've made a PR on your repo ManevilleF#1

Copy link
Member

@daniel-abramov daniel-abramov left a comment

Choose a reason for hiding this comment

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

NB: These changes might indeed be useful, but the CI pipeline fails. I also think writing a couple of tests for the subprotocol functionality would be useful.

@Its-Just-Nans
Copy link
Contributor

@ManevilleF I'v made PR once again on your repo to correct doc (once again 😅) and add a test

Link to the PR: ManevilleF#2

Maybe after you merged it @daniel-abramov could merge this one!

@daniel-abramov daniel-abramov mentioned this pull request Feb 5, 2024
@daniel-abramov
Copy link
Member

Nice. Btw, one of the CI steps fails. I did not check it in a detail, but my first guess is that the new example might require enabling some features.

@Its-Just-Nans
Copy link
Contributor

Its-Just-Nans commented Feb 5, 2024

Thanks for the tip !

@ManevilleF If you add

#![cfg(feature = "handshake")]

at the top of the test file

I guess it should work ?

@daniel-abramov daniel-abramov merged commit 0fa4197 into snapview:master Feb 12, 2024
6 checks passed
@daniel-abramov daniel-abramov mentioned this pull request Mar 7, 2024
emilk added a commit to rerun-io/ewebsock that referenced this pull request Oct 10, 2024
Hello,

In the native app, the Websocket protocol can lead to error because it
doesn't act like the web interface.

When we are using the WebSocket API (in the browser), it add
automatically some headers - like the `Origin` header.

In fact this header is mandatory, as explained in the RFC :

- <https://datatracker.ietf.org/doc/html/rfc6455>

```text
8.   The request MUST include a header field with the name |Origin|
        [[RFC6454](https://datatracker.ietf.org/doc/html/rfc6454)] if the request is coming from a browser client.  If
        the connection is from a non-browser client, the request MAY
        include this header field if the semantics of that client match
        the use-case described here for browser clients.  The value of
        this header field is the ASCII serialization of origin of the
        context in which the code establishing the connection is
        running.  See [[RFC6454](https://datatracker.ietf.org/doc/html/rfc6454)] for the details of how this header field
        value is constructed.
```


However, if we don't set the `Origin` header in the native app, the app
"could" not act the same as in the browser


In this PR, I had the Origin header to the client.

Note that
- the PR to add a header in tungstenite is quite new :
snapview/tungstenite-rs#400
- a new version of tungstenite has not been released yet (so this PR is
kind of a draft)

Thanks

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
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