Skip to content

Commit e3ae1a5

Browse files
authored
fix(client): correct handling of Sequence[Proxy] types (#568)
1 parent 8eff131 commit e3ae1a5

5 files changed

Lines changed: 9 additions & 26 deletions

File tree

python/wreq/wreq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ class ClientConfig(TypedDict):
715715

716716
proxies: NotRequired[Sequence[Proxy]]
717717
"""
718-
Add a `Proxy` list to the client.
718+
The proxies to use for requests.
719719
"""
720720

721721
local_address: NotRequired[IPv4Address | IPv6Address]

src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
use pyo3::{IntoPyObjectExt, coroutine::CancelHandle, prelude::*, pybacked::PyBackedStr};
1616
use req::{Request, WebSocketRequest};
1717
use tokio_util::sync::CancellationToken;
18-
use wreq::{Proxy, tls::trust::CertStore};
18+
use wreq::tls::trust::CertStore;
1919

2020
use self::{
2121
nogil::NoGIL,
@@ -32,6 +32,7 @@ use crate::{
3232
http::Method,
3333
http1::Http1Options,
3434
http2::Http2Options,
35+
proxy::Proxy,
3536
redirect,
3637
tls::{Identity, KeyLog, TlsOptions, TlsVerify, TlsVersion},
3738
};
@@ -141,8 +142,8 @@ struct Builder {
141142
// ========= Network options =========
142143
/// Whether to disable the proxy for the client.
143144
no_proxy: Option<bool>,
144-
/// The proxy to use for the client.
145-
proxies: Option<Extractor<Vec<Proxy>>>,
145+
/// The proxies to use for the client.
146+
proxies: Option<Vec<Proxy>>,
146147
/// Bind to a local IP Address.
147148
local_address: Option<IpAddr>,
148149
/// Bind to local IP Addresses (IPv4, IPv6).

src/client/resp/http.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ impl Display for Response {
290290
}
291291

292292
impl Drop for Response {
293+
#[inline]
293294
fn drop(&mut self) {
294295
self.destroy();
295296
}

src/extractor.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
22

3-
use pyo3::{FromPyObject, prelude::*, types::PyList};
4-
5-
use crate::proxy::Proxy;
3+
use pyo3::{FromPyObject, prelude::*};
64

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

10-
impl FromPyObject<'_, '_> for Extractor<Vec<wreq::Proxy>> {
11-
type Error = PyErr;
12-
13-
fn extract(ob: Borrowed<PyAny>) -> PyResult<Self> {
14-
let proxies = ob.cast::<PyList>()?;
15-
let len = proxies.len();
16-
proxies
17-
.iter()
18-
.try_fold(Vec::with_capacity(len), |mut list, proxy| {
19-
let proxy = proxy.cast::<Proxy>()?;
20-
list.push(proxy.borrow().0.clone());
21-
Ok::<_, PyErr>(list)
22-
})
23-
.map(Self)
24-
}
25-
}
26-
278
impl FromPyObject<'_, '_> for Extractor<(Option<Ipv4Addr>, Option<Ipv6Addr>)> {
289
type Error = PyErr;
2910

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ macro_rules! apply_option {
5454
};
5555
(set_if_some_iter_inner, $builder:expr, $option:expr, $method:ident) => {
5656
if let Some(value) = $option.take() {
57-
for item in value.0 {
58-
$builder = $builder.$method(item);
57+
for item in value {
58+
$builder = $builder.$method(item.0);
5959
}
6060
}
6161
};

0 commit comments

Comments
 (0)