pub struct HttpResponse {
pub status: u16,
pub headers: Vec<(String, String)>,
pub content_length: Option<u64>,
pub resumed: bool,
pub url: String,
/* private fields */
}Expand description
What a server answered, with its body still to be read.
Fields§
§status: u16The status line’s code.
headers: Vec<(String, String)>The response headers, with their names lower-cased.
content_length: Option<u64>How long the body is, when the server said.
resumed: boolWhether the server honoured HttpRequest::resume_from.
false from a resumed request means the body starts at the beginning
again, and a caller appending to a partial file must truncate it first.
url: StringThe URL the request went to, for the errors reading the body reports.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(url: impl Into<String>, status: u16, body: HttpBodyRef) -> Self
pub fn new(url: impl Into<String>, status: u16, body: HttpBodyRef) -> Self
Builds a response around a body.
Sourcepub fn empty(url: impl Into<String>, status: u16) -> Self
pub fn empty(url: impl Into<String>, status: u16) -> Self
A response with no body, which is what a HEAD answers with.
Sourcepub fn with_headers(self, headers: Vec<(String, String)>) -> Self
pub fn with_headers(self, headers: Vec<(String, String)>) -> Self
Sets the response headers as name and value pairs.
Sourcepub fn with_content_length(self, content_length: Option<u64>) -> Self
pub fn with_content_length(self, content_length: Option<u64>) -> Self
Sets the length of the body in bytes, when the server said.
Sourcepub fn with_resumed(self, resumed: bool) -> Self
pub fn with_resumed(self, resumed: bool) -> Self
Sets whether the server honoured HttpRequest::resume_from.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the status is in the 2xx range.
Sourcepub fn error_for_status(self) -> Result<Self, HttpError>
pub fn error_for_status(self) -> Result<Self, HttpError>
Fails with HttpError::HttpStatus unless the status is a success.
Sourcepub async fn read_chunk(&self) -> Result<Option<Vec<u8>>, HttpError>
pub async fn read_chunk(&self) -> Result<Option<Vec<u8>>, HttpError>
The next chunk of the body, or None at its end.