Skip to content
Open
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
7 changes: 0 additions & 7 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ dependencies = [
"base64 0.22.1",
"chrono",
"log",
"punycode",
"rustls",
"rustls-native-certs",
"rustls-webpki",
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 0 additions & 7 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ dependencies = [
"base64 0.22.1",
"chrono",
"log",
"punycode",
"rustls",
"rustls-native-certs",
"rustls-webpki",
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions bitreq/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]
Expand Down
9 changes: 4 additions & 5 deletions bitreq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 2 additions & 34 deletions bitreq/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseLazy, Error> {
pub(crate) fn send_https(self) -> Result<ResponseLazy, Error> {
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")]
Expand All @@ -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<ResponseLazy, Error> {
pub(crate) fn send(self) -> Result<ResponseLazy, Error> {
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")]
Expand Down Expand Up @@ -313,35 +310,6 @@ fn get_redirect(mut connection: Connection, status_code: i32, url: Option<&Strin
}
}

fn ensure_ascii_host(host: String) -> Result<String, Error> {
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.
///
Expand Down
10 changes: 0 additions & 10 deletions bitreq/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
13 changes: 1 addition & 12 deletions bitreq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down