diff --git a/Cargo.toml b/Cargo.toml index ddceccd0..e0323b58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ bytes = "1.10.1" futures-util = { version = "0.3.31", default-features = false } http = "1" http-body-util = "0.1.3" -wreq = { version = "6.0.0-rc.12", features = [ +wreq = { version = "6.0.0-rc.13", features = [ "json", "socks", "stream", diff --git a/python/rnet/__init__.pyi b/python/rnet/__init__.pyi index e181ba07..3198e571 100644 --- a/python/rnet/__init__.pyi +++ b/python/rnet/__init__.pyi @@ -545,10 +545,10 @@ class Response: Get the local address of the response. """ - def history(self) -> List[History]: - r""" - Get the redirect history of the Response. - """ + history: List[History] + r""" + Get the redirect history of the Response. + """ def peer_certificate(self) -> Optional[bytes]: r""" @@ -611,6 +611,8 @@ class History: headers: HeaderMap """Get the headers of the redirect response.""" + def __str__(self) -> str: ... + class SocketAddr: r""" A IP socket address. diff --git a/python/rnet/blocking.py b/python/rnet/blocking.py index 0c08c197..f07a971f 100644 --- a/python/rnet/blocking.py +++ b/python/rnet/blocking.py @@ -365,10 +365,10 @@ class Response: Get the local address of the response. """ - def history(self) -> List[History]: - r""" - Get the redirect history of the Response. - """ + history: List[History] + r""" + Get the redirect history of the Response. + """ def peer_certificate(self) -> Optional[bytes]: r""" diff --git a/src/client/response/history.rs b/src/client/response/history.rs index c4add21e..f7a01d0e 100644 --- a/src/client/response/history.rs +++ b/src/client/response/history.rs @@ -1,9 +1,11 @@ +use std::fmt::{self, Debug}; + use pyo3::prelude::*; use crate::http::header::HeaderMap; /// An entry in the redirect history. -#[pyclass(subclass, frozen)] +#[pyclass(subclass, frozen, str)] pub struct History(wreq::redirect::History); #[pymethods] @@ -38,3 +40,9 @@ impl From for History { History(history) } } + +impl fmt::Display for History { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} diff --git a/src/client/response/http.rs b/src/client/response/http.rs index afeaa70f..20f699a2 100644 --- a/src/client/response/http.rs +++ b/src/client/response/http.rs @@ -152,6 +152,7 @@ impl Response { } /// Get the redirect history of the Response. + #[getter] pub fn history(&self, py: Python) -> Vec { py.allow_threads(|| { self.ext_response() diff --git a/tests/redirect_test.py b/tests/redirect_test.py index 011f9890..3ce667a4 100644 --- a/tests/redirect_test.py +++ b/tests/redirect_test.py @@ -52,7 +52,7 @@ async def test_client_redirec_history(): assert response.status.is_success() assert response.url == "https://www.google.com/" - history = response.history() + history = response.history assert len(history) == 1 history[0].url == "https://www.google.com/" history[0].previous == url