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

Update soketto requirement from 0.6 to 0.7 #493

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ hyper = { version = "0.14.10", features = ["full"] }
log = "0.4"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
soketto = "0.6"
soketto = "0.7"
tokio = { version = "1", features = ["net", "rt-multi-thread", "macros", "time"] }
tokio-util = { version = "0.6", features = ["compat"] }
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ log = { version = "0.4", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false, features = ["alloc", "raw_value", "std"] }
thiserror = "1.0"
soketto = "0.6"
soketto = "0.7"
hyper = "0.14.10"
3 changes: 2 additions & 1 deletion ws-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ tokio = { version = "1", features = ["net", "time", "rt-multi-thread", "macros"]
tokio-rustls = "0.22"
tokio-util = { version = "0.6", features = ["compat"] }

arrayvec = "0.7.1"
async-trait = "0.1"
fnv = "1"
futures = { version = "0.3.14", default-features = false, features = ["std"] }
jsonrpsee-types = { path = "../types", version = "0.3.0" }
log = "0.4"
serde = "1"
serde_json = "1"
soketto = "0.6"
soketto = "0.7"
pin-project = "1"
thiserror = "1"
url = "2"
Expand Down
10 changes: 8 additions & 2 deletions ws-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use arrayvec::ArrayVec;
use futures::io::{BufReader, BufWriter};
use futures::prelude::*;
use soketto::connection;
use soketto::handshake::client::{Client as WsRawClient, ServerResponse};
use soketto::handshake::client::{Client as WsRawClient, Header, ServerResponse};
use std::{borrow::Cow, io, net::SocketAddr, sync::Arc, time::Duration};
use thiserror::Error;
use tokio::net::TcpStream;
Expand Down Expand Up @@ -234,10 +235,15 @@ impl<'a> WsTransportClientBuilder<'a> {
&self.target.host_header,
&self.target.path_and_query,
);

let mut headers: ArrayVec<Header, 1> = ArrayVec::new();

if let Some(origin) = self.origin_header.as_ref() {
client.set_origin(origin);
headers.push(Header { name: "Origin", value: origin.as_bytes() });
}

client.set_headers(&headers);
Comment on lines +239 to +245
Copy link
Contributor

Choose a reason for hiding this comment

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

dq: why not do all this inside the if let Some(origin)… clause?

Copy link
Contributor

@maciejhirsz maciejhirsz Oct 1, 2021

Choose a reason for hiding this comment

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

headers have to be defined outside of the if block to satisfy lifetimes, and it seemed more natural to me to set headers on the same scope they are defined.

Copy link
Member

@niklasad1 niklasad1 Oct 4, 2021

Choose a reason for hiding this comment

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

@maciejhirsz I did it slightly different in #397 but this is quite neat not re-export Header from this library but I did it with an array instead. So not sure why ArrayVec dep is needed but maybe I did some refactoring with the redirect loop to make it work not sure.

let origin = self.origin_header.map(|o| [o]);
let client = some_code();
if let Some(o) = origin {
   client.set_headers(o);
}
...

Copy link
Member

@niklasad1 niklasad1 Oct 5, 2021

Choose a reason for hiding this comment

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

ah I see now, origin is borrowed in the header and ☝️ won't work.


// Perform the initial handshake.
match client.handshake().await? {
ServerResponse::Accepted { .. } => {}
Expand Down
2 changes: 1 addition & 1 deletion ws-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jsonrpsee-types = { path = "../types", version = "0.3.0" }
jsonrpsee-utils = { path = "../utils", version = "0.3.0", features = ["server"] }
log = "0.4"
serde_json = { version = "1", features = ["raw_value"] }
soketto = "0.6"
soketto = "0.7"
tokio = { version = "1", features = ["net", "rt-multi-thread", "macros"] }
tokio-util = { version = "0.6", features = ["compat"] }

Expand Down