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 Options::additional_headers and subprotocols #27

Merged
merged 30 commits into from
Oct 10, 2024

Conversation

Its-Just-Nans
Copy link
Contributor

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 :

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

Thanks

log = "0.4"

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tungstenite = { version = ">=0.17, <=0.20" }
tungstenite = { version = ">=0.17, <=0.21" }
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be set to the version number of the first tungstenite release with the with_header function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right !
I'm waiting for the new version. I'm tagging the PR as DRAFT to wait for it

@Its-Just-Nans
Copy link
Contributor Author

Its-Just-Nans commented May 13, 2024

When tungstenite 0.22.0 will be out, this PR should fix

Now waiting for the version bump

@Its-Just-Nans Its-Just-Nans marked this pull request as ready for review June 2, 2024 09:21
@Its-Just-Nans
Copy link
Contributor Author

Its-Just-Nans commented Jun 2, 2024

Hi

tungstenite is now at 0.22 https://img.shields.io/crates/v/tungstenite

Note that when the 0.23 will be out, it could be more convenient to use it (see snapview/tungstenite-rs#427)

@Its-Just-Nans Its-Just-Nans requested a review from emilk June 2, 2024 09:23
@Its-Just-Nans
Copy link
Contributor Author

There migth be a problem with tokio-tungstenite right now snapview/tokio-tungstenite#334

(that's breaking my local CI/CD on my repo https://github.com/Its-Just-Nans/ewebsock/actions/runs/9337202702)

@Its-Just-Nans
Copy link
Contributor Author

tungstenite and tokio-tungstenite are now at 0.23 !

I think this is mergeable now (local CI/CD pass: https://github.com/Its-Just-Nans/ewebsock/actions/runs/9338012481)

@Its-Just-Nans
Copy link
Contributor Author

Its-Just-Nans commented Jun 3, 2024

Fixed the typo @emilk

not sure if I can fix the label https://github.com/rerun-io/ewebsock/actions/runs/9338753874/job/25722267954

Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but this PR now does three very different things:

A) replaces shell scripts with trunk
B) updates to tungstenite to 0.23
C) add default headers to the options

I would be thankful if you could break it into three PRs because

  • it would be a lot easier to review
  • it would be easier to revert one thing if we regret it
  • it would be easier to git-bisect bugs in the future

echo_server/src/main.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
ewebsock/src/lib.rs Outdated Show resolved Hide resolved
ewebsock/src/lib.rs Outdated Show resolved Hide resolved
ewebsock/src/lib.rs Outdated Show resolved Hide resolved
ewebsock/src/lib.rs Outdated Show resolved Hide resolved
ewebsock/src/native_tungstenite.rs Outdated Show resolved Hide resolved
@Its-Just-Nans
Copy link
Contributor Author

okay, here my next steps:

  • fix the current pr according to review
  • create 3 PRs

This was referenced Jun 5, 2024
@Its-Just-Nans
Copy link
Contributor Author

@emilk I've done the PR for

  • A) replaces shell scripts with trunk
  • B) updates to tungstenite to 0.23

I'm waiting for B) to be merge to edit this PR to make C)

  • C) add default headers to the options

@Its-Just-Nans Its-Just-Nans requested a review from emilk June 15, 2024 09:59
emilk pushed a commit that referenced this pull request Oct 10, 2024
Cargo.lock Outdated
@@ -4,9 +4,9 @@ version = 3

[[package]]
name = "ab_glyph"
version = "0.2.23"
Copy link
Member

Choose a reason for hiding this comment

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

Please revert all changes to Cargo.lock

@emilk emilk added the include in changelog Include this in CHANGELOG.md label Oct 10, 2024
ewebsock/src/lib.rs Outdated Show resolved Hide resolved
@emilk emilk changed the title Add Origin Header in native app Add Options::additional_headers and subprotocols Oct 10, 2024
@emilk emilk merged commit 50c510e into rerun-io:main Oct 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include in changelog Include this in CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants