some more logging

This commit is contained in:
Sean McArthur
2014-11-10 16:10:52 -08:00
parent 358edc0d2b
commit bb45ac509d
4 changed files with 26 additions and 7 deletions

View File

@@ -106,6 +106,7 @@ impl Headers {
loop {
match try!(http::read_header(rdr)) {
Some((name, value)) => {
debug!("raw header: {}={}", name, value);
let name = CaseInsensitive(Owned(name));
let item = match headers.data.entry(name) {
Vacant(entry) => entry.set(RWLock::new(Item::raw(vec![]))),

View File

@@ -324,7 +324,7 @@ pub fn read_method<R: Reader>(stream: &mut R) -> HttpResult<method::Method> {
return Err(HttpMethodError);
}
debug!("method: {}", buf[].to_ascii());
debug!("method buf = {}", buf[].to_ascii());
let maybe_method = match buf[0..7] {
b"GET " => Some(method::Get),
@@ -339,14 +339,16 @@ pub fn read_method<R: Reader>(stream: &mut R) -> HttpResult<method::Method> {
_ => None,
};
debug!("maybe_method = {}", maybe_method);
match (maybe_method, buf[]) {
(Some(method), _) => Ok(method),
(None, ext) if is_valid_method(buf) => {
use std::str::raw;
// We already checked that the buffer is ASCII
// We already checked that the buffer is ASCII
Ok(method::Extension(unsafe { raw::from_utf8(ext) }.trim().into_string()))
},
_ => Err(HttpMethodError)
_ => Err(HttpMethodError)
}
}
@@ -381,6 +383,8 @@ pub fn read_uri<R: Reader>(stream: &mut R) -> HttpResult<uri::RequestUri> {
}
}
debug!("uri buf = {}", s);
if s.as_slice().starts_with("/") {
Ok(uri::AbsolutePath(s))
} else if s.as_slice().contains("/") {
@@ -472,7 +476,7 @@ pub fn read_header<R: Reader>(stream: &mut R) -> HttpResult<Option<RawHeaderLine
let mut value = vec![];
loop {
match try_io!(stream.read_byte()) {
match inspect!("header byte", try_io!(stream.read_byte())) {
CR if name.len() == 0 => {
match try_io!(stream.read_byte()) {
LF => return Ok(None),
@@ -485,6 +489,8 @@ pub fn read_header<R: Reader>(stream: &mut R) -> HttpResult<Option<RawHeaderLine
};
}
debug!("header name = {}", name);
let mut ows = true; //optional whitespace
todo!("handle obs-folding (gross!)");
@@ -500,6 +506,8 @@ pub fn read_header<R: Reader>(stream: &mut R) -> HttpResult<Option<RawHeaderLine
};
}
debug!("header value = {}", value);
match try_io!(stream.read_byte()) {
LF => Ok(Some((name, value))),
_ => Err(HttpHeaderError)
@@ -513,8 +521,11 @@ pub type RequestLine = (method::Method, uri::RequestUri, HttpVersion);
/// Read the `RequestLine`, such as `GET / HTTP/1.1`.
pub fn read_request_line<R: Reader>(stream: &mut R) -> HttpResult<RequestLine> {
let method = try!(read_method(stream));
debug!("method = {}", method);
let uri = try!(read_uri(stream));
debug!("uri = {}", uri);
let version = try!(read_http_version(stream));
debug!("version = {}", version);
if try_io!(stream.read_byte()) != CR {
return Err(HttpVersionError);

View File

@@ -177,6 +177,14 @@ macro_rules! trace(
})
)
macro_rules! inspect(
($name:expr, $value:expr) => ({
let v = $value;
debug!("inspect: $name = {}", v);
v
})
)
pub mod client;
pub mod method;
pub mod header;

View File

@@ -40,10 +40,9 @@ impl Request {
debug!("remote addr = {}", remote_addr);
let mut stream = BufferedReader::new(box stream as Box<NetworkStream + Send>);
let (method, uri, version) = try!(read_request_line(&mut stream));
debug!("Request Line: {} {} {}", method, uri, version);
let headers = try!(Headers::from_raw(&mut stream));
debug!("{} {} {}", method, uri, version);
debug!("{}", headers);
debug!("Headers: [\n{}]", headers);
let body = if headers.has::<ContentLength>() {