perf(http): changes http parsing to use httparse crate

httparse is a http1 stateless push parser. This not only speeds up
parsing right now with sync io, but will also be useful for when we get
async io, since it's push based instead of pull.

BREAKING CHANGE: Several public functions and types in the `http` module
  have been removed. They have been replaced with 2 methods that handle
  all of the http1 parsing.
This commit is contained in:
Sean McArthur
2015-03-12 14:01:52 -07:00
parent 003b6551cf
commit b87bb20f0c
15 changed files with 358 additions and 731 deletions

View File

@@ -7,7 +7,7 @@ use header;
use header::{ContentLength, TransferEncoding};
use header::Encoding::Chunked;
use net::{NetworkStream, HttpStream};
use http::{read_status_line, HttpReader, RawStatus};
use http::{self, HttpReader, RawStatus};
use http::HttpReader::{SizedReader, ChunkedReader, EofReader};
use status;
use version;
@@ -36,15 +36,17 @@ impl Response {
/// Creates a new response from a server.
pub fn new(stream: Box<NetworkStream + Send>) -> HttpResult<Response> {
let mut stream = BufReader::new(stream);
let (version, raw_status) = try!(read_status_line(&mut stream));
let head = try!(http::parse_response(&mut stream));
let raw_status = head.subject;
let headers = head.headers;
let status = match FromPrimitive::from_u16(raw_status.0) {
Some(status) => status,
None => return Err(HttpStatusError)
};
debug!("{:?} {:?}", version, status);
let headers = try!(header::Headers::from_raw(&mut stream));
debug!("Headers: [\n{:?}]", headers);
debug!("version={:?}, status={:?}", head.version, status);
debug!("headers={:?}", headers);
let body = if headers.has::<TransferEncoding>() {
match headers.get::<TransferEncoding>() {
@@ -74,7 +76,7 @@ impl Response {
Ok(Response {
status: status,
version: version,
version: head.version,
headers: headers,
body: body,
status_raw: raw_status,