Skip to main content

HttpResponse

Struct HttpResponse 

Source
pub struct HttpResponse {
    pub meta: HttpResponseMeta,
    /* private fields */
}
Expand description

Unified HTTP response with lazily consumed body.

Fields§

§meta: HttpResponseMeta

Response metadata (status, headers, final URL, request method).

Implementations§

Source§

impl HttpResponse

Source

pub fn new( status: StatusCode, headers: HeaderMap, body: Bytes, url: Url, method: Method, ) -> Self

Creates a buffered response.

Source

pub fn meta(&self) -> &HttpResponseMeta

Returns shared response metadata.

Source

pub fn status(&self) -> StatusCode

Returns response status code.

Source

pub fn headers(&self) -> &HeaderMap

Returns response headers.

Source

pub fn url(&self) -> &Url

Returns final response URL.

Source

pub fn request_url(&self) -> &Url

Returns request URL used in response read context.

Source

pub fn is_success(&self) -> bool

Returns whether status is success.

Source

pub fn retry_after_hint(&self) -> Option<Duration>

Returns parsed Retry-After hint when status and headers provide one.

Source

pub async fn bytes(&mut self) -> HttpResult<Bytes>

Returns full body bytes, consuming backend stream lazily on first call.

Source

pub fn stream(&mut self) -> HttpResult<HttpByteStream>

Returns body as stream; if already buffered, returns stream backed by cached bytes.

Source

pub async fn text(&mut self) -> HttpResult<String>

Interprets response body as UTF-8 text.

Source

pub async fn json<T>(&mut self) -> HttpResult<T>

Deserializes response body as JSON.

Source

pub fn sse_max_line_bytes(self, max_line_bytes: usize) -> Self

Overrides the maximum allowed size (in bytes) for one SSE line on this response.

Values below 1 are clamped to 1. Returns self so callers can chain configuration before consuming the body with Self::sse_events or Self::sse_chunks (together with Self::sse_json_mode, Self::sse_done_marker_policy, etc.).

Source

pub fn sse_max_frame_bytes(self, max_frame_bytes: usize) -> Self

Overrides the maximum allowed size (in bytes) for one SSE frame on this response.

Values below 1 are clamped to 1. Returns self for chained configuration.

Source

pub fn sse_json_mode(self, mode: SseJsonMode) -> Self

Overrides the JSON decoding mode used by Self::sse_chunks on this response.

Source

pub fn sse_done_marker_policy(self, policy: DoneMarkerPolicy) -> Self

Overrides how Self::sse_chunks detects end-of-stream from trimmed data: payloads.

Source

pub fn sse_events(self) -> SseEventStream

Decodes body stream as SSE events using this response’s SSE line/frame byte limits (from client defaults unless overridden via Self::sse_max_line_bytes / Self::sse_max_frame_bytes).

Source

pub fn sse_chunks<T>(self) -> SseChunkStream<T>
where T: DeserializeOwned + Send + 'static,

Decodes SSE data: lines as JSON chunks using this response’s SSE JSON mode, done-marker policy, and line/frame limits (see Self::sse_json_mode, Self::sse_done_marker_policy, Self::sse_max_line_bytes, Self::sse_max_frame_bytes).

Trait Implementations§

Source§

impl Debug for HttpResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, D> IntoConfigDefault<T> for D
where D: IntoValueDefault<T>,

Source§

fn into_config_default(self) -> T

Converts this fallback value into T.
Source§

impl<T> IntoResult<T> for T

Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more