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

chore(pool): Use Mutex types that do not poison themselves #192

Merged
merged 3 commits into from
Dec 21, 2024
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ tower-service = "0.3"
futures-core = { version = "0.3.0", default-features = false }
futures-util = { version = "0.3.0", default-features = false }
sync_wrapper = { version = "1.0", features = ["futures"] }
antidote = { version = "1" }

# Optional deps...

Expand Down Expand Up @@ -112,7 +113,6 @@ typed-builder = { version = "0.20.0" }
# boring-tls session cache
linked_hash_set = { version = "0.1" }
tower-layer = { version = "0.3" }
antidote = { version = "1" }

# cert compression
brotli = { version = "7" }
Expand All @@ -129,7 +129,7 @@ cookie_store = { version = "0.21", optional = true }

## compression
async-compression = { version = "0.4.0", default-features = false, features = ["tokio"], optional = true }
tokio-util = { version = "0.7.9", default-features = false, features = ["codec", "io"], optional = true }
tokio-util = { version = "0.7.0", default-features = false, features = ["codec", "io"], optional = true }

## socks
tokio-socks = { version = "0.5.2", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions src/client/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Body {
/// # Example
///
/// ```
/// # use reqwest::Body;
/// # use rquest::Body;
/// # use futures_util;
/// # fn main() {
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec![
Expand Down Expand Up @@ -131,7 +131,7 @@ impl Body {
/// # Example
///
/// ```
/// # use reqwest::Body;
/// # use rquest::Body;
/// # use futures_util;
/// # fn main() {
/// let content = "hello,world!".to_string();
Expand Down
15 changes: 0 additions & 15 deletions src/client/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ pub(super) struct Accepts {
pub(super) deflate: bool,
}

impl Accepts {
pub fn none() -> Self {
Self {
#[cfg(feature = "gzip")]
gzip: false,
#[cfg(feature = "brotli")]
brotli: false,
#[cfg(feature = "zstd")]
zstd: false,
#[cfg(feature = "deflate")]
deflate: false,
}
}
}

/// A response decompressor over a non-blocking stream of chunks.
///
/// The inner decoder may be constructed asynchronously.
Expand Down
2 changes: 1 addition & 1 deletion src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ impl ClientBuilder {
///
/// ```
/// let interface = "lo";
/// let client = reqwest::Client::builder()
/// let client = rquest::Client::builder()
/// .interface(interface)
/// .build().unwrap();
/// ```
Expand Down
83 changes: 12 additions & 71 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::pin::Pin;
use std::time::Duration;

use bytes::Bytes;
use http_body_util::BodyExt;
use hyper2::{HeaderMap, StatusCode, Version};
#[cfg(feature = "json")]
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -150,7 +149,7 @@ impl Response {
///
/// ```
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let content = reqwest::get("http://httpbin.org/range/26")
/// let content = rquest::get("http://httpbin.org/range/26")
/// .await?
/// .text()
/// .await?;
Expand Down Expand Up @@ -193,7 +192,7 @@ impl Response {
///
/// ```
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let content = reqwest::get("http://httpbin.org/range/26")
/// let content = rquest::get("http://httpbin.org/range/26")
/// .await?
/// .text_with_charset("utf-8")
/// .await?;
Expand Down Expand Up @@ -231,10 +230,10 @@ impl Response {
/// # Examples
///
/// ```
/// # extern crate reqwest;
/// # extern crate rquest;
/// # extern crate serde;
/// #
/// # use reqwest::Error;
/// # use rquest::Error;
/// # use serde::Deserialize;
/// #
/// // This `derive` requires the `serde` dependency.
Expand All @@ -244,7 +243,7 @@ impl Response {
/// }
///
/// # async fn run() -> Result<(), Error> {
/// let ip = reqwest::get("http://httpbin.org/ip")
/// let ip = rquest::get("http://httpbin.org/ip")
/// .await?
/// .json::<Ip>()
/// .await?;
Expand Down Expand Up @@ -277,7 +276,7 @@ impl Response {
///
/// ```
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let bytes = reqwest::get("http://httpbin.org/ip")
/// let bytes = rquest::get("http://httpbin.org/ip")
/// .await?
/// .bytes()
/// .await?;
Expand All @@ -302,7 +301,7 @@ impl Response {
///
/// ```
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let mut res = reqwest::get("https://hyper.rs").await?;
/// let mut res = rquest::get("https://hyper.rs").await?;
///
/// while let Some(chunk) = res.chunk().await? {
/// println!("Chunk: {chunk:?}");
Expand Down Expand Up @@ -335,7 +334,7 @@ impl Response {
/// use futures_util::StreamExt;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let mut stream = reqwest::get("http://httpbin.org/ip")
/// let mut stream = rquest::get("http://httpbin.org/ip")
/// .await?
/// .bytes_stream();
///
Expand All @@ -362,7 +361,7 @@ impl Response {
/// # Example
///
/// ```
/// # use reqwest::Response;
/// # use rquest::Response;
/// fn on_response(res: Response) {
/// match res.error_for_status() {
/// Ok(_res) => (),
Expand All @@ -371,7 +370,7 @@ impl Response {
/// // it could be any status between 400...599
/// assert_eq!(
/// err.status(),
/// Some(reqwest::StatusCode::BAD_REQUEST)
/// Some(rquest::StatusCode::BAD_REQUEST)
/// );
/// }
/// }
Expand All @@ -392,7 +391,7 @@ impl Response {
/// # Example
///
/// ```
/// # use reqwest::Response;
/// # use rquest::Response;
/// fn on_response(res: &Response) {
/// match res.error_for_status_ref() {
/// Ok(_res) => (),
Expand All @@ -401,7 +400,7 @@ impl Response {
/// // it could be any status between 400...599
/// assert_eq!(
/// err.status(),
/// Some(reqwest::StatusCode::BAD_REQUEST)
/// Some(rquest::StatusCode::BAD_REQUEST)
/// );
/// }
/// }
Expand Down Expand Up @@ -434,61 +433,3 @@ impl From<Response> for Body {
Body::wrap(r.res.into_body())
}
}

// I'm not sure this conversion is that useful... People should be encouraged
// to use `http::Response`, not `reqwest::Response`.
impl<T: Into<Body>> From<http::Response<T>> for Response {
fn from(r: http::Response<T>) -> Response {
use crate::response::ResponseUrl;

let (mut parts, body) = r.into_parts();
let body: super::body::Body = body.into();
let decoder = Decoder::detect(
&mut parts.headers,
ResponseBody::new(body.map_err(Into::into)),
Accepts::none(),
);
let url = parts
.extensions
.remove::<ResponseUrl>()
.unwrap_or_else(|| ResponseUrl(Url::parse("http://no.url.provided.local").unwrap()));
let url = url.0;
let res = hyper2::Response::from_parts(parts, decoder);
Response {
res,
url: Box::new(url),
}
}
}

/// A `Response` can be converted into a `http::Response`.
// It's supposed to be the inverse of the conversion above.
impl From<Response> for http::Response<Body> {
fn from(r: Response) -> http::Response<Body> {
let (parts, body) = r.res.into_parts();
let body = Body::wrap(body);
http::Response::from_parts(parts, body)
}
}

#[cfg(test)]
mod tests {
use super::Response;
use crate::ResponseBuilderExt;
use http::response::Builder;
use url::Url;

#[test]
fn test_from_http_response() {
let url = Url::parse("http://example.com").unwrap();
let response = Builder::new()
.status(200)
.url(url.clone())
.body("foo")
.unwrap();
let response = Response::from(response);

assert_eq!(response.status(), 200);
assert_eq!(*response.url(), url);
}
}
10 changes: 5 additions & 5 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::borrow::Cow;
use std::future::Future;
use std::io::{self, IoSlice};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::ops::Deref;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -271,7 +272,7 @@ impl Connector {
}

let mut http = tls.create_connector(http, dst.version());
let io = http.call(dst.uri().clone()).await?;
let io = http.call(dst.deref().clone()).await?;

if let MaybeHttpsStream::Https(stream) = io {
if !self.nodelay {
Expand All @@ -297,7 +298,7 @@ impl Connector {
mut dst: ConnectRequest,
proxy_scheme: ProxyScheme,
) -> Result<Conn, BoxError> {
log::debug!("proxy({:?}) intercepts '{:?}'", proxy_scheme, dst.uri());
log::debug!("proxy({:?}) intercepts '{:?}'", proxy_scheme, dst);

let (proxy_dst, auth) = match proxy_scheme {
ProxyScheme::Http { host, auth } => (into_uri(Scheme::HTTP, host)?, auth),
Expand Down Expand Up @@ -373,11 +374,10 @@ impl Service<ConnectRequest> for Connector {
}

fn call(&mut self, dst: ConnectRequest) -> Self::Future {
let uri = dst.uri();
log::debug!("starting new connection: {:?}", uri);
log::debug!("starting new connection: {:?}", dst);
let timeout = self.timeout;
for prox in self.proxies.iter() {
if let Some(proxy_scheme) = prox.intercept(uri) {
if let Some(proxy_scheme) = prox.intercept(dst.deref()) {
return Box::pin(with_timeout(
self.clone().connect_via_proxy(dst, proxy_scheme),
timeout,
Expand Down
2 changes: 1 addition & 1 deletion src/dns/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Addrs = Box<dyn Iterator<Item = SocketAddr> + Send>;
/// Alias for the `Future` type returned by a DNS resolver.
pub type Resolving = Pin<Box<dyn Future<Output = Result<Addrs, BoxError>> + Send>>;

/// Trait for customizing DNS resolution in reqwest.
/// Trait for customizing DNS resolution in rquest.
pub trait Resolve: Send + Sync {
/// Performs DNS resolution on a `Name`.
/// The return type is a future containing an iterator of `SocketAddr`.
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,9 @@ pub use url::Url;
#[macro_use]
mod error;
mod into_url;
mod response;

pub use self::error::{Error, Result};
pub use self::into_url::IntoUrl;
pub use self::response::ResponseBuilderExt;

/// Shortcut method to quickly make a `GET` request.
///
Expand Down
41 changes: 0 additions & 41 deletions src/response.rs

This file was deleted.

Loading