some more logging
This commit is contained in:
@@ -106,6 +106,7 @@ impl Headers {
|
|||||||
loop {
|
loop {
|
||||||
match try!(http::read_header(rdr)) {
|
match try!(http::read_header(rdr)) {
|
||||||
Some((name, value)) => {
|
Some((name, value)) => {
|
||||||
|
debug!("raw header: {}={}", name, value);
|
||||||
let name = CaseInsensitive(Owned(name));
|
let name = CaseInsensitive(Owned(name));
|
||||||
let item = match headers.data.entry(name) {
|
let item = match headers.data.entry(name) {
|
||||||
Vacant(entry) => entry.set(RWLock::new(Item::raw(vec![]))),
|
Vacant(entry) => entry.set(RWLock::new(Item::raw(vec![]))),
|
||||||
|
|||||||
19
src/http.rs
19
src/http.rs
@@ -324,7 +324,7 @@ pub fn read_method<R: Reader>(stream: &mut R) -> HttpResult<method::Method> {
|
|||||||
return Err(HttpMethodError);
|
return Err(HttpMethodError);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("method: {}", buf[].to_ascii());
|
debug!("method buf = {}", buf[].to_ascii());
|
||||||
|
|
||||||
let maybe_method = match buf[0..7] {
|
let maybe_method = match buf[0..7] {
|
||||||
b"GET " => Some(method::Get),
|
b"GET " => Some(method::Get),
|
||||||
@@ -339,14 +339,16 @@ pub fn read_method<R: Reader>(stream: &mut R) -> HttpResult<method::Method> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!("maybe_method = {}", maybe_method);
|
||||||
|
|
||||||
match (maybe_method, buf[]) {
|
match (maybe_method, buf[]) {
|
||||||
(Some(method), _) => Ok(method),
|
(Some(method), _) => Ok(method),
|
||||||
(None, ext) if is_valid_method(buf) => {
|
(None, ext) if is_valid_method(buf) => {
|
||||||
use std::str::raw;
|
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()))
|
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("/") {
|
if s.as_slice().starts_with("/") {
|
||||||
Ok(uri::AbsolutePath(s))
|
Ok(uri::AbsolutePath(s))
|
||||||
} else if s.as_slice().contains("/") {
|
} 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![];
|
let mut value = vec![];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match try_io!(stream.read_byte()) {
|
match inspect!("header byte", try_io!(stream.read_byte())) {
|
||||||
CR if name.len() == 0 => {
|
CR if name.len() == 0 => {
|
||||||
match try_io!(stream.read_byte()) {
|
match try_io!(stream.read_byte()) {
|
||||||
LF => return Ok(None),
|
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
|
let mut ows = true; //optional whitespace
|
||||||
|
|
||||||
todo!("handle obs-folding (gross!)");
|
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()) {
|
match try_io!(stream.read_byte()) {
|
||||||
LF => Ok(Some((name, value))),
|
LF => Ok(Some((name, value))),
|
||||||
_ => Err(HttpHeaderError)
|
_ => Err(HttpHeaderError)
|
||||||
@@ -513,8 +521,11 @@ pub type RequestLine = (method::Method, uri::RequestUri, HttpVersion);
|
|||||||
/// Read the `RequestLine`, such as `GET / HTTP/1.1`.
|
/// Read the `RequestLine`, such as `GET / HTTP/1.1`.
|
||||||
pub fn read_request_line<R: Reader>(stream: &mut R) -> HttpResult<RequestLine> {
|
pub fn read_request_line<R: Reader>(stream: &mut R) -> HttpResult<RequestLine> {
|
||||||
let method = try!(read_method(stream));
|
let method = try!(read_method(stream));
|
||||||
|
debug!("method = {}", method);
|
||||||
let uri = try!(read_uri(stream));
|
let uri = try!(read_uri(stream));
|
||||||
|
debug!("uri = {}", uri);
|
||||||
let version = try!(read_http_version(stream));
|
let version = try!(read_http_version(stream));
|
||||||
|
debug!("version = {}", version);
|
||||||
|
|
||||||
if try_io!(stream.read_byte()) != CR {
|
if try_io!(stream.read_byte()) != CR {
|
||||||
return Err(HttpVersionError);
|
return Err(HttpVersionError);
|
||||||
|
|||||||
@@ -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 client;
|
||||||
pub mod method;
|
pub mod method;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
|
|||||||
@@ -40,10 +40,9 @@ impl Request {
|
|||||||
debug!("remote addr = {}", remote_addr);
|
debug!("remote addr = {}", remote_addr);
|
||||||
let mut stream = BufferedReader::new(box stream as Box<NetworkStream + Send>);
|
let mut stream = BufferedReader::new(box stream as Box<NetworkStream + Send>);
|
||||||
let (method, uri, version) = try!(read_request_line(&mut stream));
|
let (method, uri, version) = try!(read_request_line(&mut stream));
|
||||||
|
debug!("Request Line: {} {} {}", method, uri, version);
|
||||||
let headers = try!(Headers::from_raw(&mut stream));
|
let headers = try!(Headers::from_raw(&mut stream));
|
||||||
|
debug!("Headers: [\n{}]", headers);
|
||||||
debug!("{} {} {}", method, uri, version);
|
|
||||||
debug!("{}", headers);
|
|
||||||
|
|
||||||
|
|
||||||
let body = if headers.has::<ContentLength>() {
|
let body = if headers.has::<ContentLength>() {
|
||||||
|
|||||||
Reference in New Issue
Block a user