Struct http_muncher::Parser
[−]
[src]
pub struct Parser { /* fields omitted */ }
The main parser interface.
Example
use http_muncher::{Parser, ParserHandler}; use std::str; struct MyHandler; impl ParserHandler for MyHandler { fn on_header_field(&mut self, parser: &mut Parser, header: &[u8]) -> bool { println!("{}: ", str::from_utf8(header).unwrap()); true } fn on_header_value(&mut self, parser: &mut Parser, value: &[u8]) -> bool { println!("\t {:?}", str::from_utf8(value).unwrap()); true } } let http_request = b"GET / HTTP/1.0\r\n\ Content-Length: 0\r\n\r\n"; let mut parser = Parser::request(); parser.parse(&mut MyHandler {}, http_request);
Methods
impl Parser
[src]
pub fn response() -> Parser
[src]
Creates a new parser instance for an HTTP response.
pub fn request() -> Parser
[src]
Creates a new parser instance for an HTTP request.
pub fn request_and_response() -> Parser
[src]
Creates a new parser instance to handle both HTTP requests and responses.
pub fn parse<H: ParserHandler>(&mut self, handler: &mut H, data: &[u8]) -> usize
[src]
Parses the provided data
and returns a number of bytes read.
pub fn http_version(&self) -> (u16, u16)
[src]
Returns an HTTP request or response version.
pub fn status_code(&self) -> u16
[src]
Returns an HTTP response status code (think 404).
pub fn http_method(&self) -> &'static str
[src]
Returns an HTTP method static string (GET
, POST
, and so on).
pub fn has_error(&self) -> bool
[src]
Checks if the last parse
call was finished successfully.
Returns true
if it wasn't.
pub fn error(&self) -> &'static str
[src]
In case of a parsing error returns its mnemonic name.
pub fn error_description(&self) -> &'static str
[src]
In case of a parsing error returns its description.
pub fn is_upgrade(&self) -> bool
[src]
Checks if an upgrade protocol (e.g. WebSocket) was requested.
pub fn is_final_chunk(&self) -> bool
[src]
Checks if it was the final body chunk.
pub fn should_keep_alive(&self) -> bool
[src]
If should_keep_alive()
in the on_headers_complete
or on_message_complete
callback
returns 0, then this should be the last message on the connection.
If you are the server, respond with the "Connection: close" header.
If you are the client, close the connection.