diff --git a/examples/raw_upload/src/main.rs b/examples/raw_upload/src/main.rs index 59e0df52..8f34d71a 100644 --- a/examples/raw_upload/src/main.rs +++ b/examples/raw_upload/src/main.rs @@ -3,19 +3,14 @@ extern crate rocket; +use std::io; + use rocket::request::Data; -use rocket::response::Failure; -use rocket::http::StatusCode; +use rocket::response::data::Plain; #[post("/upload", format = "text/plain", data = "")] -fn upload(data: Data) -> Result { - match data.stream_to_file("/tmp/upload.txt") { - Ok(n) => Ok(format!("OK: {} bytes uploaded.", n)), - Err(e) => { - println!(" => Failed writing to file: {:?}.", e); - return Err(Failure(StatusCode::InternalServerError)); - } - } +fn upload(data: Data) -> io::Result> { + data.stream_to_file("/tmp/upload.txt").map(|n| Plain(n.to_string())) } #[get("/")] diff --git a/lib/src/request/request.rs b/lib/src/request/request.rs index eb3f3e38..3d3f8141 100644 --- a/lib/src/request/request.rs +++ b/lib/src/request/request.rs @@ -220,6 +220,11 @@ impl fmt::Display for Request { /// Pretty prints a Request. This is primarily used by Rocket's logging /// infrastructure. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} {}", Green.paint(&self.method), Blue.paint(&self.uri)) + write!(f, "{} {}", Green.paint(&self.method), Blue.paint(&self.uri))?; + if self.method.supports_payload() && !self.content_type().is_any() { + write!(f, " {}", Yellow.paint(self.content_type()))?; + } + + Ok(()) } } diff --git a/lib/src/router/route.rs b/lib/src/router/route.rs index 9373149e..fbd8aba6 100644 --- a/lib/src/router/route.rs +++ b/lib/src/router/route.rs @@ -138,6 +138,6 @@ impl Collider for Route { fn collides_with(&self, req: &Request) -> bool { self.method == req.method && req.uri().collides_with(&self.path.as_uri()) - && req.accepts().collides_with(&self.content_type) + && req.content_type().collides_with(&self.content_type) } }