pub struct Response { /* private fields */ }Expand description
A network response.
This type represents an HTTP response and provides access to response details such as status, headers, and body.
Implementations§
Source§impl Response
impl Response
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Get the response URL.
This may differ from the request URL in case of redirects.
Sourcepub fn status_text(&self) -> &str
pub fn status_text(&self) -> &str
Get the HTTP status text.
Sourcepub fn header_value(&self, name: &str) -> Option<&str>
pub fn header_value(&self, name: &str) -> Option<&str>
Get a header value by name (case-insensitive).
Sourcepub async fn all_headers(&self) -> HashMap<String, String>
pub async fn all_headers(&self) -> HashMap<String, String>
Get all headers asynchronously.
This may fetch additional headers that weren’t available synchronously.
Sourcepub fn from_cache(&self) -> bool
pub fn from_cache(&self) -> bool
Check if the response was served from cache.
Sourcepub fn from_service_worker(&self) -> bool
pub fn from_service_worker(&self) -> bool
Check if the response was served from a service worker.
Sourcepub async fn text(&self) -> Result<String, NetworkError>
pub async fn text(&self) -> Result<String, NetworkError>
Get the response body as text.
§Errors
Returns an error if the body cannot be fetched or is not valid UTF-8.
Sourcepub async fn json<T: DeserializeOwned>(&self) -> Result<T, NetworkError>
pub async fn json<T: DeserializeOwned>(&self) -> Result<T, NetworkError>
Parse the response body as JSON.
§Errors
Returns an error if the body cannot be fetched or is not valid JSON.
Sourcepub fn security_details(&self) -> Option<&SecurityDetails>
pub fn security_details(&self) -> Option<&SecurityDetails>
Get security details for HTTPS responses.
Sourcepub fn server_addr(&self) -> Option<&RemoteAddress>
pub fn server_addr(&self) -> Option<&RemoteAddress>
Get the remote server address.
Sourcepub async fn finished(&self) -> Result<(), NetworkError>
pub async fn finished(&self) -> Result<(), NetworkError>
Wait for the response body to be fully received.