Skip to content
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 python/wreq/wreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ class ClientConfig(TypedDict):

proxies: NotRequired[Sequence[Proxy]]
"""
Add a `Proxy` list to the client.
The proxies to use for requests.
"""

local_address: NotRequired[IPv4Address | IPv6Address]
Expand Down
7 changes: 4 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
use pyo3::{IntoPyObjectExt, coroutine::CancelHandle, prelude::*, pybacked::PyBackedStr};
use req::{Request, WebSocketRequest};
use tokio_util::sync::CancellationToken;
use wreq::{Proxy, tls::trust::CertStore};
use wreq::tls::trust::CertStore;

use self::{
nogil::NoGIL,
Expand All @@ -32,6 +32,7 @@ use crate::{
http::Method,
http1::Http1Options,
http2::Http2Options,
proxy::Proxy,
redirect,
tls::{Identity, KeyLog, TlsOptions, TlsVerify, TlsVersion},
};
Expand Down Expand Up @@ -141,8 +142,8 @@ struct Builder {
// ========= Network options =========
/// Whether to disable the proxy for the client.
no_proxy: Option<bool>,
/// The proxy to use for the client.
proxies: Option<Extractor<Vec<Proxy>>>,
/// The proxies to use for the client.
proxies: Option<Vec<Proxy>>,
/// Bind to a local IP Address.
local_address: Option<IpAddr>,
/// Bind to local IP Addresses (IPv4, IPv6).
Expand Down
1 change: 1 addition & 0 deletions src/client/resp/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl Display for Response {
}

impl Drop for Response {
#[inline]
fn drop(&mut self) {
self.destroy();
}
Expand Down
21 changes: 1 addition & 20 deletions src/extractor.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

use pyo3::{FromPyObject, prelude::*, types::PyList};

use crate::proxy::Proxy;
use pyo3::{FromPyObject, prelude::*};

/// A generic extractor for various types.
pub struct Extractor<T>(pub T);

impl FromPyObject<'_, '_> for Extractor<Vec<wreq::Proxy>> {
type Error = PyErr;

fn extract(ob: Borrowed<PyAny>) -> PyResult<Self> {
let proxies = ob.cast::<PyList>()?;
let len = proxies.len();
proxies
.iter()
.try_fold(Vec::with_capacity(len), |mut list, proxy| {
let proxy = proxy.cast::<Proxy>()?;
list.push(proxy.borrow().0.clone());
Ok::<_, PyErr>(list)
})
.map(Self)
}
}

impl FromPyObject<'_, '_> for Extractor<(Option<Ipv4Addr>, Option<Ipv6Addr>)> {
type Error = PyErr;

Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ macro_rules! apply_option {
};
(set_if_some_iter_inner, $builder:expr, $option:expr, $method:ident) => {
if let Some(value) = $option.take() {
for item in value.0 {
$builder = $builder.$method(item);
for item in value {
$builder = $builder.$method(item.0);
Comment thread
0x676e67 marked this conversation as resolved.
}
}
};
Expand Down
Loading