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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions python/rnet/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions python/rnet/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
10 changes: 9 additions & 1 deletion src/client/response/history.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -38,3 +40,9 @@ impl From<wreq::redirect::History> for History {
History(history)
}
}

impl fmt::Display for History {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
1 change: 1 addition & 0 deletions src/client/response/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Response {
}

/// Get the redirect history of the Response.
#[getter]
pub fn history(&self, py: Python) -> Vec<History> {
py.allow_threads(|| {
self.ext_response()
Expand Down
2 changes: 1 addition & 1 deletion tests/redirect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading