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
Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. 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: Arc<dyn HttpBody + Send + Sync>,
) -> HttpResponse
pub fn new( url: impl Into<String>, status: u16, body: Arc<dyn HttpBody + Send + Sync>, ) -> HttpResponse
Builds a response around a body.
Sourcepub fn empty(url: impl Into<String>, status: u16) -> HttpResponse
pub fn empty(url: impl Into<String>, status: u16) -> HttpResponse
A response with no body, which is what a HEAD answers with.
pub fn with_headers(self, headers: Vec<(String, String)>) -> HttpResponse
pub fn with_content_length(self, content_length: Option<u64>) -> HttpResponse
pub fn with_resumed(self, resumed: bool) -> HttpResponse
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<HttpResponse, HttpError>
pub fn error_for_status(self) -> Result<HttpResponse, 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.