From f3e4445f9293abc76c8206f4b40f7fe5fa879661 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 22 May 2023 16:40:07 +1200 Subject: [PATCH] Update dependencies --- Cargo.toml | 34 +++++++++++++++++----------------- examples/next_reuse.rs | 2 +- src/client.rs | 20 ++++++++++---------- src/request.rs | 33 +++++++++++++++++++++------------ src/request_builder.rs | 23 ++++++++++++++--------- src/response.rs | 29 +++++++++++++++++++---------- tests/test.rs | 4 ++-- wasm-test/Cargo.toml | 6 +++--- 8 files changed, 87 insertions(+), 64 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5145188..dfe3cee0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,30 +58,30 @@ middleware-logger = [] encoding = ["encoding_rs", "web-sys"] [dependencies] -futures-util = { version = "0.3.5", features = ["io"] } -log = { version = "0.4.7", features = ["kv_unstable"] } -mime_guess = "2.0.3" -serde = "1.0.97" -serde_json = "1.0.40" -http-client = { version = "6.5.0", default-features = false } -http-types = "2.5.0" -async-std = { version = "1.6.0", default-features = false, features = ["std"] } -async-trait = "0.1.36" -pin-project-lite = "0.2.0" -once_cell = { version = "1.4.1", optional = true } +futures-util = { version = "0.3.28", features = ["io"] } +log = { version = "0.4.17", features = ["kv_unstable"] } +mime_guess = "2.0.4" +serde = "1.0.163" +serde_json = "1.0.96" +http-client = { git = "https://github.com/expenses/http-client-patched", branch = "update-deps", default-features = false } +http-types = { git = "https://github.com/http-rs/http-types", rev = "ac5d645ce5294554b86ebd49233d3ec01665d1d7" } +async-std = { version = "1.12.0", default-features = false, features = ["std"] } +async-trait = "0.1.68" +pin-project-lite = "0.2.9" +once_cell = { version = "1.17.1", optional = true } cfg-if = "1.0.0" -getrandom = "0.2.0" -encoding_rs = { version = "0.8.20", optional = true } +getrandom = "0.2.9" +encoding_rs = { version = "0.8.32", optional = true } rustls_crate = { version = "0.18", optional = true, package = "rustls" } async-native-tls = { version = "0.3.3", optional = true } -web-sys = { optional = true, version = "0.3.25", features = ["TextDecoder"] } +web-sys = { optional = true, version = "0.3.63", features = ["TextDecoder"] } [dev-dependencies] -async-std = { version = "1.6.0", features = ["attributes"] } -femme = "1.1.0" -serde = { version = "1.0.97", features = ["derive"] } +async-std = { version = "1.12.0", features = ["attributes"] } +femme = "1.3.0" +serde = { version = "1.0.163", features = ["derive"] } mockito = "0.23.3" tide = "0.16.0" diff --git a/examples/next_reuse.rs b/examples/next_reuse.rs index 7dc18e17..8895ae1b 100644 --- a/examples/next_reuse.rs +++ b/examples/next_reuse.rs @@ -20,7 +20,7 @@ impl Middleware for Doubler { let mut new_req: Request = new_req.into(); for (name, value) in &req { - new_req.insert_header(name, value); + new_req.insert_header(name, value)?; } let mut buf = Vec::new(); diff --git a/src/client.rs b/src/client.rs index b0591507..552a6e24 100644 --- a/src/client.rs +++ b/src/client.rs @@ -336,7 +336,7 @@ impl Client { /// let string = client.get("https://httpbin.org/get").recv_string().await?; /// # Ok(()) } /// ``` - pub fn get(&self, uri: impl AsRef) -> RequestBuilder { + pub fn get(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Get, self.url(uri)).with_client(self.clone()) } @@ -359,7 +359,7 @@ impl Client { /// let string = client.head("https://httpbin.org/head").recv_string().await?; /// # Ok(()) } /// ``` - pub fn head(&self, uri: impl AsRef) -> RequestBuilder { + pub fn head(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Head, self.url(uri)).with_client(self.clone()) } @@ -382,7 +382,7 @@ impl Client { /// let string = client.post("https://httpbin.org/post").recv_string().await?; /// # Ok(()) } /// ``` - pub fn post(&self, uri: impl AsRef) -> RequestBuilder { + pub fn post(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Post, self.url(uri)).with_client(self.clone()) } @@ -405,7 +405,7 @@ impl Client { /// let string = client.put("https://httpbin.org/put").recv_string().await?; /// # Ok(()) } /// ``` - pub fn put(&self, uri: impl AsRef) -> RequestBuilder { + pub fn put(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Put, self.url(uri)).with_client(self.clone()) } @@ -428,7 +428,7 @@ impl Client { /// let string = client.delete("https://httpbin.org/delete").recv_string().await?; /// # Ok(()) } /// ``` - pub fn delete(&self, uri: impl AsRef) -> RequestBuilder { + pub fn delete(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Delete, self.url(uri)).with_client(self.clone()) } @@ -451,7 +451,7 @@ impl Client { /// let string = client.connect("https://httpbin.org/connect").recv_string().await?; /// # Ok(()) } /// ``` - pub fn connect(&self, uri: impl AsRef) -> RequestBuilder { + pub fn connect(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Connect, self.url(uri)).with_client(self.clone()) } @@ -474,7 +474,7 @@ impl Client { /// let string = client.options("https://httpbin.org/options").recv_string().await?; /// # Ok(()) } /// ``` - pub fn options(&self, uri: impl AsRef) -> RequestBuilder { + pub fn options(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Options, self.url(uri)).with_client(self.clone()) } @@ -497,7 +497,7 @@ impl Client { /// let string = client.trace("https://httpbin.org/trace").recv_string().await?; /// # Ok(()) } /// ``` - pub fn trace(&self, uri: impl AsRef) -> RequestBuilder { + pub fn trace(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Trace, self.url(uri)).with_client(self.clone()) } @@ -520,7 +520,7 @@ impl Client { /// let string = client.patch("https://httpbin.org/patch").recv_string().await?; /// # Ok(()) } /// ``` - pub fn patch(&self, uri: impl AsRef) -> RequestBuilder { + pub fn patch(&self, uri: impl AsRef) -> crate::Result { RequestBuilder::new(Method::Patch, self.url(uri)).with_client(self.clone()) } @@ -544,7 +544,7 @@ impl Client { /// let res = client.send(req).await?; /// # Ok(()) } /// ``` - pub fn request(&self, verb: Method, uri: impl AsRef) -> RequestBuilder { + pub fn request(&self, verb: Method, uri: impl AsRef) -> crate::Result { RequestBuilder::new(verb, self.url(uri)).with_client(self.clone()) } diff --git a/src/request.rs b/src/request.rs index bb83500e..aa70130f 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,7 +1,8 @@ use crate::http::{ self, headers::{self, HeaderName, HeaderValues, ToHeaderValues}, - Body, Method, Mime, Url, + mime::Mime, + Body, Method, Url, }; use crate::middleware::Middleware; use crate::RequestBuilder; @@ -146,7 +147,7 @@ impl Request { &mut self, name: impl Into, values: impl ToHeaderValues, - ) -> Option { + ) -> crate::Result> { self.req.insert_header(name, values) } @@ -154,7 +155,11 @@ impl Request { /// /// Unlike `insert` this function will not override the contents of a header, but insert a /// header if there aren't any. Or else append to the existing list of headers. - pub fn append_header(&mut self, name: impl Into, values: impl ToHeaderValues) { + pub fn append_header( + &mut self, + name: impl Into, + values: impl ToHeaderValues, + ) -> crate::Result<()> { self.req.append_header(name, values) } @@ -200,8 +205,12 @@ impl Request { /// assert_eq!(req.header("X-Requested-With").unwrap(), "surf"); /// # Ok(()) } /// ``` - pub fn set_header(&mut self, key: impl Into, value: impl ToHeaderValues) { - self.insert_header(key, value); + pub fn set_header( + &mut self, + key: impl Into, + value: impl ToHeaderValues, + ) -> crate::Result> { + self.insert_header(key, value) } /// Get a request extension value. @@ -276,7 +285,7 @@ impl Request { /// value to decide whether to use `Chunked` encoding, or set the /// response length. #[allow(clippy::len_without_is_empty)] - pub fn len(&self) -> Option { + pub fn len(&self) -> Option { self.req.len() } @@ -351,8 +360,8 @@ impl Request { /// /// This method will return an error if the file couldn't be read. #[cfg(not(target_arch = "wasm32"))] - pub async fn body_file(&mut self, path: impl AsRef) -> std::io::Result<()> { - self.set_body(Body::from_file(path).await?); + pub async fn body_file(&mut self, file: async_std::fs::File) -> std::io::Result<()> { + self.set_body(Body::from_file(file).await?); Ok(()) } @@ -400,14 +409,14 @@ impl Request { } } -impl AsRef for Request { - fn as_ref(&self) -> &http::Headers { +impl AsRef for Request { + fn as_ref(&self) -> &http::headers::Headers { self.req.as_ref() } } -impl AsMut for Request { - fn as_mut(&mut self) -> &mut http::Headers { +impl AsMut for Request { + fn as_mut(&mut self) -> &mut http::headers::Headers { self.req.as_mut() } } diff --git a/src/request_builder.rs b/src/request_builder.rs index 5ba8b948..7f2141b1 100644 --- a/src/request_builder.rs +++ b/src/request_builder.rs @@ -1,6 +1,7 @@ use crate::http::{ headers::{HeaderName, ToHeaderValues}, - Body, Method, Mime, Url, + mime::Mime, + Body, Method, Url, }; use crate::middleware::Middleware; use crate::{Client, Error, Request, Response, Result}; @@ -85,15 +86,15 @@ impl RequestBuilder { } } - pub(crate) fn with_client(mut self, client: Client) -> Self { + pub(crate) fn with_client(mut self, client: Client) -> crate::Result { let req = self.req.as_mut().unwrap(); for (header_name, header_values) in client.config().headers.iter() { - req.append_header(header_name, header_values); + req.append_header(header_name, header_values)?; } self.client = Some(client); - self + Ok(self) } /// Sets a header on the request. @@ -104,9 +105,13 @@ impl RequestBuilder { /// let req = surf::get("https://httpbin.org/get").header("header-name", "header-value").build(); /// assert_eq!(req["header-name"], "header-value"); /// ``` - pub fn header(mut self, key: impl Into, value: impl ToHeaderValues) -> Self { - self.req.as_mut().unwrap().insert_header(key, value); - self + pub fn header( + mut self, + key: impl Into, + value: impl ToHeaderValues, + ) -> crate::Result { + self.req.as_mut().unwrap().insert_header(key, value)?; + Ok(self) } /// Sets the Content-Type header on the request. @@ -245,8 +250,8 @@ impl RequestBuilder { /// # Ok(()) } /// ``` #[cfg(not(target_arch = "wasm32"))] - pub async fn body_file(self, path: impl AsRef) -> std::io::Result { - Ok(self.body(Body::from_file(path).await?)) + pub async fn body_file(self, file: async_std::fs::File) -> std::io::Result { + Ok(self.body(Body::from_file(file).await?)) } /// Set the URL querystring. diff --git a/src/response.rs b/src/response.rs index 2ed10b70..9d95db2c 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,7 +1,8 @@ use crate::http::{ self, headers::{self, HeaderName, HeaderValues, ToHeaderValues}, - Body, Error, Mime, StatusCode, Version, + mime::Mime, + Body, Error, StatusCode, Version, }; use async_std::io::BufRead; @@ -86,13 +87,21 @@ impl Response { } /// Insert an HTTP header. - pub fn insert_header(&mut self, key: impl Into, value: impl ToHeaderValues) { - self.res.insert_header(key, value); + pub fn insert_header( + &mut self, + key: impl Into, + value: impl ToHeaderValues, + ) -> crate::Result> { + self.res.insert_header(key, value) } /// Append an HTTP header. - pub fn append_header(&mut self, key: impl Into, value: impl ToHeaderValues) { - self.res.append_header(key, value); + pub fn append_header( + &mut self, + key: impl Into, + value: impl ToHeaderValues, + ) -> crate::Result<()> { + self.res.append_header(key, value) } /// An iterator visiting all header pairs in arbitrary order. @@ -162,7 +171,7 @@ impl Response { /// value to decide whether to use `Chunked` encoding, or set the /// response length. #[allow(clippy::len_without_is_empty)] - pub fn len(&self) -> Option { + pub fn len(&self) -> Option { self.res.len() } @@ -329,14 +338,14 @@ impl Into for Response { } } -impl AsRef for Response { - fn as_ref(&self) -> &http::Headers { +impl AsRef for Response { + fn as_ref(&self) -> &http::headers::Headers { self.res.as_ref() } } -impl AsMut for Response { - fn as_mut(&mut self) -> &mut http::Headers { +impl AsMut for Response { + fn as_mut(&mut self) -> &mut http::headers::Headers { self.res.as_mut() } } diff --git a/tests/test.rs b/tests/test.rs index 39d075c9..9f66763c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -24,7 +24,7 @@ async fn post_json() -> Result<(), http_types::Error> { .with_body(&serde_json::to_string(&cat)?[..]) .create(); let res = surf::post(mockito::server_url()) - .header("Accept", "application/json") + .header("Accept", "application/json")? .body(Body::from_json(&cat)?) .await?; m.assert(); @@ -192,7 +192,7 @@ async fn config_client_headers() -> Result<(), http_types::Error> { .add_header("X-Header-Name", "X-Header-Values")? .try_into()?; - let res = client.get("http://example.org/").await?; + let res = client.get("http://example.org/")?.await?; assert_eq!(res["X-Header-Name"], "X-Header-Values"); diff --git a/wasm-test/Cargo.toml b/wasm-test/Cargo.toml index 906a379b..52073402 100644 --- a/wasm-test/Cargo.toml +++ b/wasm-test/Cargo.toml @@ -5,7 +5,7 @@ edition = "2018" [dependencies] surf = { path = "..", default-features = false, features = ["wasm-client"] } -wasm-bindgen-test = "0.3.24" -async-std = "1.6.4" -serde_json = "1.0.57" +wasm-bindgen-test = "0.3.36" +async-std = "1.12.0" +serde_json = "1.0.96"