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 rnet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ class Response:
"""
...

def stream(self) -> typing.Any:
def stream(self) -> Streamer:
r"""
Returns the stream content of the response.

Expand Down
4 changes: 0 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* Copyright (c) 2025
* All rights reserved.
*/
use crate::{
error::{wrap_invali_header_name_error, wrap_rquest_error},
param::{ClientParams, RequestParams},
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use client::Client;
use param::{ClientParams, RequestParams};
use pyo3::prelude::*;
use pyo3_stub_gen::{define_stub_info_gatherer, derive::*};
use resp::Response;
use resp::{Response, Streamer};
use types::{HeaderMap, Impersonate, Method, Proxy, SocketAddr, StatusCode, Version};

type Result<T> = std::result::Result<T, PyErr>;
Expand Down Expand Up @@ -253,6 +253,7 @@ fn rnet(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<RequestParams>()?;
m.add_class::<StatusCode>()?;
m.add_class::<Response>()?;
m.add_class::<Streamer>()?;
m.add_class::<Client>()?;
m.add_function(wrap_pyfunction!(request, m)?)?;
m.add_function(wrap_pyfunction!(get, m)?)?;
Expand Down
14 changes: 10 additions & 4 deletions src/resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl Response {
///
/// A string representing the URL of the response.
#[getter]
#[inline(always)]
pub fn url(&self) -> &str {
self.url.as_str()
}
Expand All @@ -80,6 +81,7 @@ impl Response {
///
/// A boolean indicating whether the response is successful.
#[getter]
#[inline(always)]
pub fn ok(&self) -> bool {
self.status_code.is_success()
}
Expand All @@ -90,6 +92,7 @@ impl Response {
///
/// A Python object representing the HTTP status code.
#[getter]
#[inline(always)]
pub fn status_code(&self) -> StatusCode {
self.status_code
}
Expand All @@ -100,6 +103,7 @@ impl Response {
///
/// A `Version` object representing the HTTP version of the response.
#[getter]
#[inline(always)]
pub fn version(&self) -> Version {
self.version
}
Expand All @@ -110,6 +114,7 @@ impl Response {
///
/// A `HeaderMap` object representing the headers of the response.
#[getter]
#[inline(always)]
pub fn headers(&self) -> HeaderMap {
self.headers.clone()
}
Expand All @@ -120,6 +125,7 @@ impl Response {
///
/// An integer representing the content length of the response.
#[getter]
#[inline(always)]
pub fn content_length(&self) -> u64 {
self.content_length.unwrap_or_default()
}
Expand All @@ -130,6 +136,7 @@ impl Response {
///
/// An `IpAddr` object representing the remote address of the response.
#[getter]
#[inline(always)]
pub fn remote_addr(&self) -> Option<SocketAddr> {
self.remote_addr.map(SocketAddr::from)
}
Expand Down Expand Up @@ -284,9 +291,8 @@ impl Response {
/// # Returns
///
/// A Python object representing the stream content of the response.
pub fn stream<'rt>(&self, py: Python<'rt>) -> PyResult<Bound<'rt, PyAny>> {
let streamer = self.into_inner().map(Streamer::new)?;
streamer.into_bound_py_any(py)
pub fn stream(&self) -> PyResult<Streamer> {
self.into_inner().map(Streamer::new)
}

/// Closes the response connection.
Expand Down Expand Up @@ -349,7 +355,7 @@ impl Response {
/// ```
#[gen_stub_pyclass]
#[pyclass]
struct Streamer(Arc<Mutex<rquest::Response>>);
pub struct Streamer(Arc<Mutex<rquest::Response>>);

impl Streamer {
/// Creates a new `Streamer` instance.
Expand Down