diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 835e598c..39c90165 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -161,7 +161,6 @@ dependencies = [ "base64 0.22.1", "chrono", "log", - "punycode", "rustls", "rustls-native-certs", "rustls-webpki", @@ -542,12 +541,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "punycode" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe" - [[package]] name = "quote" version = "1.0.36" diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 0eb54056..66d72923 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -161,7 +161,6 @@ dependencies = [ "base64 0.22.1", "chrono", "log", - "punycode", "rustls", "rustls-native-certs", "rustls-webpki", @@ -564,12 +563,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "punycode" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe" - [[package]] name = "quote" version = "1.0.38" diff --git a/bitreq/Cargo.toml b/bitreq/Cargo.toml index 4f01d65d..401f769b 100644 --- a/bitreq/Cargo.toml +++ b/bitreq/Cargo.toml @@ -18,8 +18,6 @@ maintenance = { status = "experimental" } [dependencies] # For the urlencoding feature: urlencoding = { version = "2.1.0", optional = true } -# For the punycode feature: -punycode = { version = "0.4.1", optional = true } # For the json-using-serde feature: serde = { version = "1.0.101", optional = true } serde_json = { version = "1.0.0", optional = true } @@ -40,7 +38,7 @@ tiny_http = "0.12" chrono = "0.4.0" [package.metadata.docs.rs] -features = ["json-using-serde", "proxy", "https", "punycode"] +features = ["json-using-serde", "proxy", "https"] [features] default = ["std"] diff --git a/bitreq/README.md b/bitreq/README.md index 0acc219b..3b02328b 100644 --- a/bitreq/README.md +++ b/bitreq/README.md @@ -7,11 +7,10 @@ This crate is a fork for the very nice rename it because I wanted to totally gut it and provide a crate with different goals. Many thanks to the original author. -Simple, minimal-dependency HTTP client. Optional features for -unicode domains (`punycode`), http proxies (`proxy`), async support -(`async`, `async-https`), and https with various TLS implementations -(`https-rustls`, `https-rustls-probe`, and `https` which is an alias -for `https-rustls`). +Simple, minimal-dependency HTTP client. Optional features for http +proxies (`proxy`), async support (`async`, `async-https`), and https +with various TLS implementations (`https-rustls`, `https-rustls-probe`, +and `https` which is an alias for `https-rustls`). Without any optional features, my casual testing indicates about 100 KB additional executable size for stripped release builds using this diff --git a/bitreq/src/connection.rs b/bitreq/src/connection.rs index 1595e2f6..87e053b1 100644 --- a/bitreq/src/connection.rs +++ b/bitreq/src/connection.rs @@ -150,10 +150,8 @@ impl Connection { /// Sends the [`Request`](struct.Request.html), consumes this /// connection, and returns a [`Response`](struct.Response.html). #[cfg(feature = "rustls")] - pub(crate) fn send_https(mut self) -> Result { + pub(crate) fn send_https(self) -> Result { enforce_timeout(self.timeout_at, move || { - self.request.url.host = ensure_ascii_host(self.request.url.host)?; - let secured_stream = rustls_stream::create_secured_stream(&self)?; #[cfg(feature = "log")] @@ -170,9 +168,8 @@ impl Connection { /// Sends the [`Request`](struct.Request.html), consumes this /// connection, and returns a [`Response`](struct.Response.html). - pub(crate) fn send(mut self) -> Result { + pub(crate) fn send(self) -> Result { enforce_timeout(self.timeout_at, move || { - self.request.url.host = ensure_ascii_host(self.request.url.host)?; let bytes = self.request.as_bytes(); #[cfg(feature = "log")] @@ -313,35 +310,6 @@ fn get_redirect(mut connection: Connection, status_code: i32, url: Option<&Strin } } -fn ensure_ascii_host(host: String) -> Result { - if host.is_ascii() { - Ok(host) - } else { - #[cfg(not(feature = "punycode"))] - { - Err(Error::PunycodeFeatureNotEnabled) - } - - #[cfg(feature = "punycode")] - { - let mut result = String::with_capacity(host.len() * 2); - for s in host.split('.') { - if s.is_ascii() { - result += s; - } else { - match punycode::encode(s) { - Ok(s) => result = result + "xn--" + &s, - Err(_) => return Err(Error::PunycodeConversionFailed), - } - } - result += "."; - } - result.truncate(result.len() - 1); // Remove the trailing dot - Ok(result) - } - } -} - /// Enforce the timeout by running the function in a new thread and /// parking the current one with a timeout. /// diff --git a/bitreq/src/error.rs b/bitreq/src/error.rs index dda103cd..64267bfc 100644 --- a/bitreq/src/error.rs +++ b/bitreq/src/error.rs @@ -52,18 +52,10 @@ pub enum Error { /// The response contained invalid UTF-8 where it should be valid /// (eg. headers), so the response cannot interpreted correctly. InvalidUtf8InResponse, - /// The provided url contained a domain that has non-ASCII - /// characters, and could not be converted into punycode. It is - /// probably not an actual domain. - PunycodeConversionFailed, /// Tried to send a secure request (ie. the url started with /// `https://`), but the crate's `https` feature was not enabled, /// and as such, a connection cannot be made. HttpsFeatureNotEnabled, - /// The provided url contained a domain that has non-ASCII - /// characters, but it could not be converted into punycode - /// because the `punycode` feature was not enabled. - PunycodeFeatureNotEnabled, /// The provided proxy information was not properly formatted. See /// [Proxy::new](crate::Proxy::new) for the valid format. BadProxy, @@ -110,8 +102,6 @@ impl fmt::Display for Error { TooManyRedirections => write!(f, "too many redirections (over the max)"), InvalidUtf8InResponse => write!(f, "response contained invalid utf-8 where valid utf-8 was expected"), HttpsFeatureNotEnabled => write!(f, "request url contains https:// but the https feature is not enabled"), - PunycodeFeatureNotEnabled => write!(f, "non-ascii urls needs to be converted into punycode, and the feature is missing"), - PunycodeConversionFailed => write!(f, "non-ascii url conversion to punycode failed"), BadProxy => write!(f, "the provided proxy information is malformed"), BadProxyCreds => write!(f, "the provided proxy credentials are malformed"), ProxyConnect => write!(f, "could not connect to the proxy server"), diff --git a/bitreq/src/lib.rs b/bitreq/src/lib.rs index afa718de..dd6cde7a 100644 --- a/bitreq/src/lib.rs +++ b/bitreq/src/lib.rs @@ -21,7 +21,7 @@ //! //! ```toml //! [dependencies] -//! bitreq = { version = "2.13.5-alpha", features = ["punycode"] } +//! bitreq = { version = "2.13.5-alpha", features = ["https"] } //! ``` //! //! Below is the list of all available features. @@ -45,17 +45,6 @@ //! crate to auto-detect root certificates installed in common //! locations. //! -//! ## `punycode` -//! -//! This feature enables requests to non-ascii domains: the -//! [`punycode`](https://crates.io/crates/punycode) crate is used to -//! convert the non-ascii parts into their punycode representations -//! before making the request. If you try to make a request to 㯙㯜㯙 -//! 㯟.net or i❤.ws for example, with this feature disabled (as it is -//! by default), your request will fail with a -//! [`PunycodeFeatureNotEnabled`](enum.Error.html#variant.PunycodeFeatureNotEnabled) -//! error. -//! //! ## `async` //! //! This feature enables asynchronous HTTP requests using tokio. It provides