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.
pub fn with_headers(self, headers: Vec<(String, String)>) -> Self
pub fn with_content_length(self, content_length: Option<u64>) -> Self
pub fn with_resumed(self, resumed: bool) -> Self
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.
Auto Trait Implementations§
impl !RefUnwindSafe for HttpResponse
impl !UnwindSafe for HttpResponse
impl Freeze for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more