pub struct HttpResponse {
pub status: u16,
pub headers: Vec<(String, String)>,
pub body: String,
}Expand description
An HTTP response.
Fields§
§status: u16The status code.
headers: Vec<(String, String)>The response headers, in the order the venue sent them.
Carried because the body is not the whole answer: a venue that
rate-limits says how long to wait in Retry-After, and a response
without headers throws that away before anything can read it — which is
why Error::RateLimited used to be raised with retry_after: None
at every one of its construction sites.
body: StringThe response body.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(status: u16, body: impl Into<String>) -> HttpResponse
pub fn new(status: u16, body: impl Into<String>) -> HttpResponse
Build a response with no headers.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> HttpResponse
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> HttpResponse
Add a header.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
The first value of name, matched case-insensitively.
Header names are case-insensitive per RFC 9110, and venues are not
consistent about it: the same field arrives as Retry-After from one
and retry-after from another behind HTTP/2, which lower-cases them.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
The venue’s advised wait from Retry-After, if it sent one.
Only the delta-seconds form is read. The HTTP-date form is legal but no
venue in this repository’s error taxonomy uses it, and parsing dates
would mean a date library and a clock in a function that must stay
pure — an unread None is the better failure here than a wrong
duration. Fractional seconds are accepted because some venues send
them, though the RFC specifies an integer.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the status is in the 2xx range.
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HttpResponse
impl Debug for HttpResponse
impl Eq for HttpResponse
Source§impl PartialEq for HttpResponse
impl PartialEq for HttpResponse
impl StructuralPartialEq for HttpResponse
Auto Trait Implementations§
impl Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin for HttpResponse
impl UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more