pub struct HttpParser {
pub http_version: HttpVersion,
pub errno: Option<HttpErrno>,
pub status_code: Option<u16>,
pub method: Option<HttpMethod>,
pub upgrade: bool,
pub strict: bool,
/* private fields */
}
Expand description
The HTTP parser that parses requests and responses.
§Example
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 parser = HttpParser::new(HttpParserType::Request);
let mut cb = Callback;
let line: &str = "GET / HTTP/1.1\r\n";
parser.execute(&mut cb, line.as_bytes());
Fields§
§http_version: HttpVersion
HTTP version of the request or response
errno: Option<HttpErrno>
Error number of there is an error in parsing
status_code: Option<u16>
Status code of the response
method: Option<HttpMethod>
HTTP method of the request
upgrade: bool
whether the protocol is upgraded
strict: bool
whether using strict parsing mode
Implementations§
Source§impl HttpParser
impl HttpParser
Sourcepub fn new(tp: HttpParserType) -> HttpParser
pub fn new(tp: HttpParserType) -> HttpParser
Creates a parser of the specified type.
§Example
let mut parser = HttpParser::new(HttpParserType::Request);
Sourcepub fn execute<T: HttpParserCallback>(
&mut self,
cb: &mut T,
data: &[u8],
) -> usize
pub fn execute<T: HttpParserCallback>( &mut self, cb: &mut T, data: &[u8], ) -> usize
Parses the HTTP requests or responses, specified in data
as an array of bytes.
§Example
let mut parser = HttpParser::new(HttpParserType::Request);
let mut cb = Callback;
let line: &str = "GET / HTTP/1.1\r\n";
parser.execute(&mut cb, line.as_bytes());
Sourcepub fn http_body_is_final(&self) -> bool
pub fn http_body_is_final(&self) -> bool
Returns true if the HTTP body is final.
Sourcepub fn http_should_keep_alive(&self) -> bool
pub fn http_should_keep_alive(&self) -> bool
Returns true if it needs to keep alive.
Auto Trait Implementations§
impl Freeze for HttpParser
impl RefUnwindSafe for HttpParser
impl Send for HttpParser
impl Sync for HttpParser
impl Unpin for HttpParser
impl UnwindSafe for HttpParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more