pub struct HttpResponse {
pub meta: HttpResponseMeta,
/* private fields */
}Expand description
Unified HTTP response with lazily consumed body.
Fields§
§meta: HttpResponseMetaResponse metadata (status, headers, final URL, request method).
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(
status: StatusCode,
headers: HeaderMap,
body: Bytes,
url: Url,
method: Method,
) -> Self
pub fn new( status: StatusCode, headers: HeaderMap, body: Bytes, url: Url, method: Method, ) -> Self
Creates a buffered response.
Sourcepub fn meta(&self) -> &HttpResponseMeta
pub fn meta(&self) -> &HttpResponseMeta
Returns shared response metadata.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns response status code.
Sourcepub fn request_url(&self) -> &Url
pub fn request_url(&self) -> &Url
Returns request URL used in response read context.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns whether status is success.
Sourcepub fn retry_after_hint(&self) -> Option<Duration>
pub fn retry_after_hint(&self) -> Option<Duration>
Returns parsed Retry-After hint when status and headers provide one.
Sourcepub async fn bytes(&mut self) -> HttpResult<Bytes>
pub async fn bytes(&mut self) -> HttpResult<Bytes>
Returns full body bytes, consuming backend stream lazily on first call.
Sourcepub fn stream(&mut self) -> HttpResult<HttpByteStream>
pub fn stream(&mut self) -> HttpResult<HttpByteStream>
Returns body as stream; if already buffered, returns stream backed by cached bytes.
Sourcepub async fn text(&mut self) -> HttpResult<String>
pub async fn text(&mut self) -> HttpResult<String>
Interprets response body as UTF-8 text.
Sourcepub async fn json<T>(&mut self) -> HttpResult<T>where
T: DeserializeOwned,
pub async fn json<T>(&mut self) -> HttpResult<T>where
T: DeserializeOwned,
Deserializes response body as JSON.
Sourcepub fn sse_max_line_bytes(self, max_line_bytes: usize) -> Self
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.).
Sourcepub fn sse_max_frame_bytes(self, max_frame_bytes: usize) -> Self
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.
Sourcepub fn sse_json_mode(self, mode: SseJsonMode) -> Self
pub fn sse_json_mode(self, mode: SseJsonMode) -> Self
Overrides the JSON decoding mode used by Self::sse_chunks on this response.
Sourcepub fn sse_done_marker_policy(self, policy: DoneMarkerPolicy) -> Self
pub fn sse_done_marker_policy(self, policy: DoneMarkerPolicy) -> Self
Overrides how Self::sse_chunks detects end-of-stream from trimmed data: payloads.
Sourcepub fn sse_events(self) -> SseEventStream
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).
Sourcepub fn sse_chunks<T>(self) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
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§
Auto Trait Implementations§
impl !Freeze for HttpResponse
impl !RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin for HttpResponse
impl !UnwindSafe for HttpResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.