Struct http_srv::request::HttpRequest
source · pub struct HttpRequest { /* private fields */ }
Expand description
HTTP Request
Represents an HTTP request
Implementations§
source§impl HttpRequest
impl HttpRequest
pub fn is_http_ok(&self) -> bool
pub fn is_http_err(&self) -> bool
pub fn status_msg(&self) -> &'static str
source§impl HttpRequest
impl HttpRequest
sourcepub fn parse(stream: TcpStream) -> Result<Self>
pub fn parse(stream: TcpStream) -> Result<Self>
Read and parse an HTTP request from the given TcpStream
pub fn keep_alive(self) -> Result<Self>
pub fn stream(&self) -> &TcpStream
pub fn set_url(&mut self, url: impl Into<String>)
pub fn param(&self, key: &str) -> Option<&str>
sourcepub fn filename(&self) -> Result<String>
pub fn filename(&self) -> Result<String>
Get the filename for the request
It computes the path in the server corresponding to the request’s url.
pub fn method(&self) -> &RequestMethod
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<String, String>
pub fn set_header(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn body(&mut self) -> Vec<u8>
pub fn read_body(&mut self, writer: &mut dyn Write) -> Result<()>
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
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
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
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.
sourcepub fn respond_error_page(&mut self) -> Result<()>
pub fn respond_error_page(&mut self) -> Result<()>
Respond with a basic HTML error page
Respond to the request with an 401 UNAUTHORIZED status
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
sourcepub fn error_page(&self) -> String
pub fn error_page(&self) -> String
Returns a basic HTML error page of the given status