snapview / tungstenite-rs

Lightweight stream-based WebSocket implementation for Rust.
Apache License 2.0
1.92k stars 221 forks source link

Remove requirement for handshake dependencies #296

Open Icelk opened 2 years ago

Icelk commented 2 years ago

Hi. Thanks for the great code!

Is it possible for you to add a cargo feature for the handshake code? I'm handling the handshake manually, so the dependencies pulled in (like httparse) are unnecessary.

I can make a PR if you'd like. Thanks!

daniel-abramov commented 2 years ago

Hey, thanks.

I think it's totally possible, but might result in too many #[cfg(..)] at certain places I think. As far as I understood it, additional dependencies (like httparse) is a big deal in your case, so your solution would benefit from a slightly leaner dependency, right?

Icelk commented 2 years ago

Precisely. It feels wrong to include unused code, especially whole dependencies. Increases compile time and attack vectors. But I do understand if you'd prefer not to add additional #[cfg()] attribute. The reduction of dependencies is just a nice-to-have in my case, as I've gated the entire WebSocket feature behind #[cfg()].

daniel-abramov commented 2 years ago

Got it. If it does not change the code-readability much, I would be totally ok with it :)

Icelk commented 2 years ago

Nice! Then I'll send a PR to this repo and to tokio-tungstenite this weekend. Thanks!

Icelk commented 2 years ago

@application-developer-DA I've sent the PRs :)

tqwewe commented 2 years ago

Hey @Icelk , is it currently possible to make a WebSocket instance with skipping the handshake? In my case, I'm also handling the handshake manually, but can't figure out how to use this library without the handshake.

EDIT: Nevermind! I just found tungstenite::protocol::WebSocket::from_raw_socket