pub struct HttpRequest { /* private fields */ }
Expand description
HTTP Request
Represents an HTTP request
Implementations§
Source§impl HttpRequest
impl HttpRequest
pub fn builder() -> HttpRequestBuilder
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn parse(stream: impl Into<HttpStream>) -> Result<Self>
pub fn parse(stream: impl Into<HttpStream>) -> Result<Self>
Read and parse an HTTP request from the given HttpStream
pub fn keep_alive(self) -> Result<Self>
pub fn stream(&self) -> &HttpStream ⓘ
pub fn set_url(&mut self, url: impl Into<Box<str>>)
pub fn param(&self, key: &str) -> Option<&str>
Sourcepub fn filename(&self) -> Result<Box<str>>
pub fn filename(&self) -> Result<Box<str>>
Get the filename for the request
It computes the path in the server corresponding to the request’s url.
pub fn write_to(&self, f: &mut dyn Write) -> Result<()>
Sourcepub fn send_to(&self, stream: HttpStream) -> Result<HttpResponse>
pub fn send_to(&self, stream: HttpStream) -> Result<HttpResponse>
pub fn method(&self) -> &HttpMethod
pub fn status(&self) -> u16
pub fn set_status(&mut self, status: u16) -> &mut Self
pub fn version(&self) -> f32
Sourcepub fn content_length(&self) -> usize
pub fn content_length(&self) -> usize
Get the value of the Content-Length HTTP header
If the header is not present, or if it fails to parse it’s value, it returns 0
Sourcepub fn header(&self, key: &str) -> Option<&str>
pub fn header(&self, key: &str) -> Option<&str>
Get the value of the given header key, if present
pub fn headers(&self) -> &HashMap<Box<str>, Box<str>>
pub fn set_header( &mut self, key: impl Into<Box<str>>, value: impl Into<Box<str>>, )
pub fn body(&mut self) -> Option<&[u8]>
Sourcepub fn respond(&mut self) -> Result<()>
pub fn respond(&mut self) -> Result<()>
Respond to the request without a body
§Errors
If some io error is produced while sending the request
Sourcepub fn respond_buf(&mut self, buf: &[u8]) -> Result<()>
pub fn respond_buf(&mut self, buf: &[u8]) -> Result<()>
Respond to the request with the data of buf as a body
§Errors
If some io error is produced while sending the request
Sourcepub fn respond_str(&mut self, text: &str) -> Result<()>
pub fn respond_str(&mut self, text: &str) -> Result<()>
Respond to the request with the given string
§Errors
If some io error is produced while sending the request
Sourcepub fn respond_reader(&mut self, reader: &mut dyn Read) -> Result<()>
pub fn respond_reader(&mut self, reader: &mut dyn Read) -> Result<()>
Respond to the request with the data read from reader as a body
§Errors
If some io error is produced while sending the request
Sourcepub fn respond_chunked(&mut self, reader: &mut dyn Read) -> Result<()>
pub fn respond_chunked(&mut self, reader: &mut dyn Read) -> Result<()>
Respond to the request as a chunked transfer
This means that the Content-Length of the request doen’t need to be known.
§Errors
If some io error is produced while sending the request
Sourcepub fn respond_error_page(&mut self) -> Result<()>
pub fn respond_error_page(&mut self) -> Result<()>
Sourcepub fn ok(&mut self) -> Result<()>
pub fn ok(&mut self) -> Result<()>
Respond to the request with an 200 OK status
§Errors
If some io error is produced while sending the request
Sourcepub fn forbidden(&mut self) -> Result<()>
pub fn forbidden(&mut self) -> Result<()>
Respond to the request with an 403 FORBIDDEN status
§Errors
If some io error is produced while sending the request
Respond to the request with an 401 UNAUTHORIZED status
§Errors
If some io error is produced while sending the request
Sourcepub fn not_found(&mut self) -> Result<()>
pub fn not_found(&mut self) -> Result<()>
Respond to the request with an 404 NOT FOUND status
§Errors
If some io error is produced while sending the request
Sourcepub fn server_error(&mut self) -> Result<()>
pub fn server_error(&mut self) -> Result<()>
Respond to the request with an 500 INTERNAL SERVER ERROR status
§Errors
If some io error is produced while sending the request
pub fn is_http_ok(&self) -> bool
pub fn is_http_err(&self) -> bool
pub fn status_msg(&self) -> &'static str
Sourcepub fn error_page(&self) -> String
pub fn error_page(&self) -> String
Returns a basic HTML error page of the given status