Struct http_muncher::Parser [] [src]

pub struct Parser<H> {
    // some fields omitted
}

The main parser interface.

Example

struct MyHandler;
impl ParserHandler for MyHandler {
   fn on_header_field(&self, header: &[u8]) -> bool {
       println!("{}: ", header);
       true
   }
   fn on_header_value(&self, value: &[u8]) -> bool {
       println!("\t {}", value);
       true
   }
}

let http_request = b"GET / HTTP/1.0\r\n\
                     Content-Length: 0\r\n\r\n";

Parser::request(&MyHandler).parse(http_request);

Methods

impl<H: ParserHandler> Parser<H>
[src]

fn response(handler: H) -> Parser<H>

Creates a new parser instance for an HTTP response.

Provide it with your ParserHandler trait implementation as an argument.

fn request(handler: H) -> Parser<H>

Creates a new parser instance for an HTTP request.

Provide it with your ParserHandler trait implementation as an argument.

fn request_and_response(handler: H) -> Parser<H>

Creates a new parser instance to handle both HTTP requests and responses.

Provide it with your ParserHandler trait implementation as an argument.

fn parse(&mut self, data: &[u8]) -> usize

Parses the provided data and returns a number of bytes read.

fn http_version(&self) -> (u16, u16)

Returns an HTTP request or response version.

fn status_code(&self) -> u16

Returns an HTTP response status code (think 404).

fn http_method(&self) -> &'static str

Returns an HTTP method static string (GET, POST, and so on).

fn has_error(&self) -> bool

Checks if the last parse call was finished successfully. Returns true if it wasn't.

fn error(&self) -> &'static str

In case of a parsing error returns its mnemonic name.

fn error_description(&self) -> &'static str

In case of a parsing error returns its description.

fn is_upgrade(&self) -> bool

Checks if an upgrade protocol (e.g. WebSocket) was requested.

fn is_final_chunk(&self) -> bool

Checks if it was the final body chunk.

fn get(&mut self) -> &mut H

Trait Implementations

impl<H: ParserHandler> Send for Parser<H>
[src]

impl<H: ParserHandler> Debug for Parser<H>
[src]

fn fmt(&self, fmt: &mut Formatter) -> Result<()Error>

Formats the value using the given formatter.