1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
//! # The Rust HTTP Parser //! //! The Rust HTTP Parser provides the functionality to parse both HTTP requests and responses. //! //! It is ported from [joyent/http-parser](https://github.com/joyent/http-parser) written in C. //! //! # Install //! //! Add `http_parser` to `Cargo.toml`: //! //! ```toml //! [dependencies] //! http_parser = "0.0.2" //! ``` //! //! # Usage //! //! Define a callback struct: //! //! ``` //! # use http_parser::*; //! struct Callback; //! //! impl HttpParserCallback for Callback { //! fn on_message_begin(&mut self, parser: &mut HttpParser) -> CallbackResult { //! println!("Message begin"); //! Ok(ParseAction::None) //! } //! //! // Override other functions as you wish //! } //! ``` //! //! Create an instance of `HttpParser` for requests: //! //! ``` //! # use http_parser::*; //! let mut parser = HttpParser::new(HttpParserType::Request); //! ``` //! //! Create an instance of `Callback` struct: //! //! ``` //! # use http_parser::*; //! # struct Callback; //! # //! # impl HttpParserCallback for Callback { //! # fn on_message_begin(&mut self, parser: &mut HttpParser) -> CallbackResult { //! # println!("Message begin"); //! # Ok(ParseAction::None) //! # } //! # //! # // Override other functions as you wish //! # } //! let mut cb = Callback; //! ``` //! //! Execute the parser by providing a HTTP request: //! //! ``` //! # use http_parser::*; //! # struct Callback; //! # //! # impl HttpParserCallback for Callback { //! # fn on_message_begin(&mut self, parser: &mut HttpParser) -> CallbackResult { //! # println!("Message begin"); //! # Ok(ParseAction::None) //! # } //! # //! # // Override other functions as you wish //! # } //! # let mut cb = Callback; //! # let mut parser = HttpParser::new(HttpParserType::Request); //! let line: &str = "GET / HTTP/1.1\r\n"; //! parser.execute(&mut cb, line.as_bytes()); //! ``` #![crate_name = "http_parser"] pub use self::parser::{HttpParser, HttpParserType}; pub use self::http_version::HttpVersion; pub use self::error::HttpErrno; pub use self::http_method::HttpMethod; pub use self::callback::{HttpParserCallback, CallbackResult, ParseAction}; mod parser; mod http_version; mod error; mod state; mod flags; mod http_method; mod callback;