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 buffered_body(&self) -> Option<&Bytes>
pub fn buffered_body(&self) -> Option<&Bytes>
Returns cached full body if already buffered.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns whether status is success.
Sourcepub async fn bytes_body(&mut self) -> HttpResult<Bytes>
pub async fn bytes_body(&mut self) -> HttpResult<Bytes>
Returns full body bytes, consuming backend stream lazily on first call.
Sourcepub fn stream_body(&mut self) -> HttpResult<HttpByteStream>
pub fn stream_body(&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 decode_sse_events(self) -> SseEventStream
pub fn decode_sse_events(self) -> SseEventStream
Decodes body stream as SSE events with default limits.
Sourcepub fn decode_sse_events_with_limits(
self,
max_line_bytes: usize,
max_frame_bytes: usize,
) -> SseEventStream
pub fn decode_sse_events_with_limits( self, max_line_bytes: usize, max_frame_bytes: usize, ) -> SseEventStream
Decodes body stream as SSE events with explicit limits.
Sourcepub fn decode_sse_json_chunks<T>(
self,
done_policy: DoneMarkerPolicy,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
pub fn decode_sse_json_chunks<T>(
self,
done_policy: DoneMarkerPolicy,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
Decodes SSE data chunks as JSON using response default options.
Sourcepub fn decode_sse_json_chunks_with_mode<T>(
self,
done_policy: DoneMarkerPolicy,
mode: SseJsonMode,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
pub fn decode_sse_json_chunks_with_mode<T>(
self,
done_policy: DoneMarkerPolicy,
mode: SseJsonMode,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
Decodes SSE JSON chunks with explicit mode and default limits.
Sourcepub fn decode_sse_json_chunks_with_mode_and_limits<T>(
self,
done_policy: DoneMarkerPolicy,
mode: SseJsonMode,
max_line_bytes: usize,
max_frame_bytes: usize,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
pub fn decode_sse_json_chunks_with_mode_and_limits<T>(
self,
done_policy: DoneMarkerPolicy,
mode: SseJsonMode,
max_line_bytes: usize,
max_frame_bytes: usize,
) -> SseChunkStream<T>where
T: DeserializeOwned + Send + 'static,
Decodes SSE JSON chunks with explicit mode and limits.