From 74ec26db95da013c74ffb3273b73892b5ee87b87 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 3 Oct 2016 17:09:13 -0700 Subject: [PATCH] Namespace HTTP-related type under `http`. --- codegen/src/decorators/route.rs | 16 ++++++++-------- codegen/src/parser/route.rs | 4 ++-- contrib/src/json/mod.rs | 4 ++-- contrib/src/templates/mod.rs | 11 +++++++---- examples/content_types/src/main.rs | 3 ++- examples/cookies/src/main.rs | 2 +- examples/manual_routes/src/main.rs | 2 +- examples/testing/src/main.rs | 3 ++- lib/Cargo.toml | 2 +- lib/src/catcher.rs | 11 +++++++---- lib/src/codegen.rs | 4 ++-- lib/src/{ => http}/content_type.rs | 21 ++++++++++----------- lib/src/http/cookies.rs | 4 ++++ lib/src/http/hyper.rs | 22 ++++++++++++++++++++++ lib/src/{ => http}/method.rs | 8 ++++---- lib/src/http/mod.rs | 13 +++++++++++++ lib/src/lib.rs | 16 ++++++++-------- lib/src/request/from_request.rs | 6 +++--- lib/src/request/mod.rs | 9 --------- lib/src/request/request.rs | 7 ++----- lib/src/response/data.rs | 7 ++++--- lib/src/response/empty.rs | 5 ++++- lib/src/response/flash.rs | 11 ++++++----- lib/src/response/mod.rs | 8 +------- lib/src/response/named_file.rs | 6 ++++-- lib/src/response/outcome.rs | 5 +++-- lib/src/response/redirect.rs | 3 ++- lib/src/response/responder.rs | 6 ++++-- lib/src/response/stream.rs | 4 +++- lib/src/response/with_status.rs | 3 ++- lib/src/rocket.rs | 27 +++++++++++++++------------ lib/src/router/collider.rs | 15 ++++++++------- lib/src/router/mod.rs | 11 ++++++----- lib/src/router/route.rs | 12 +++++++----- 34 files changed, 170 insertions(+), 121 deletions(-) rename lib/src/{ => http}/content_type.rs (96%) create mode 100644 lib/src/http/cookies.rs create mode 100644 lib/src/http/hyper.rs rename lib/src/{ => http}/method.rs (97%) create mode 100644 lib/src/http/mod.rs diff --git a/codegen/src/decorators/route.rs b/codegen/src/decorators/route.rs index f88992d4..fa5b50b3 100644 --- a/codegen/src/decorators/route.rs +++ b/codegen/src/decorators/route.rs @@ -14,29 +14,29 @@ use syntax::ext::build::AstBuilder; use syntax::parse::token::{self, str_to_ident}; use syntax::ptr::P; -use rocket::{Method, ContentType}; -use rocket::content_type::{TopLevel, SubLevel}; +use rocket::http::{Method, ContentType}; +use rocket::http::mime::{TopLevel, SubLevel}; fn method_to_path(ecx: &ExtCtxt, method: Method) -> Path { - quote_enum!(ecx, method => ::rocket::Method { + quote_enum!(ecx, method => ::rocket::http::Method { Options, Get, Post, Put, Delete, Head, Trace, Connect, Patch; }) } // FIXME: This should return an Expr! (Ext is not a path.) fn top_level_to_expr(ecx: &ExtCtxt, level: &TopLevel) -> Path { - quote_enum!(ecx, *level => ::rocket::content_type::TopLevel { + quote_enum!(ecx, *level => ::rocket::http::mime::TopLevel { Star, Text, Image, Audio, Video, Application, Multipart, Model, Message; - Ext(ref s) => quote_path!(ecx, ::rocket::content_type::TopLevel::Ext($s)) + Ext(ref s) => quote_path!(ecx, ::rocket::http::mime::TopLevel::Ext($s)) }) } // FIXME: This should return an Expr! (Ext is not a path.) fn sub_level_to_expr(ecx: &ExtCtxt, level: &SubLevel) -> Path { - quote_enum!(ecx, *level => ::rocket::content_type::SubLevel { + quote_enum!(ecx, *level => ::rocket::http::mime::SubLevel { Star, Plain, Html, Xml, Javascript, Css, EventStream, Json, WwwFormUrlEncoded, Msgpack, OctetStream, FormData, Png, Gif, Bmp, Jpeg; - Ext(ref s) => quote_path!(ecx, ::rocket::content_type::SubLevel::Ext($s)) + Ext(ref s) => quote_path!(ecx, ::rocket::http::mime::SubLevel::Ext($s)) }) } @@ -44,7 +44,7 @@ fn content_type_to_expr(ecx: &ExtCtxt, ct: Option) -> Option bool { - use rocket::Method::*; + use rocket::http::Method::*; match method { Get | Put | Post | Delete | Patch => true, _ => false diff --git a/contrib/src/json/mod.rs b/contrib/src/json/mod.rs index 52318831..b52e69ed 100644 --- a/contrib/src/json/mod.rs +++ b/contrib/src/json/mod.rs @@ -4,8 +4,8 @@ extern crate serde_json; use std::ops::{Deref, DerefMut}; use rocket::request::{Request, FromRequest}; -use rocket::response::{Responder, Outcome, FreshHyperResponse}; -use rocket::response::data; +use rocket::response::{Responder, Outcome, data}; +use rocket::http::hyper::FreshHyperResponse; use self::serde::{Serialize, Deserialize}; use self::serde_json::Error as JSONError; diff --git a/contrib/src/templates/mod.rs b/contrib/src/templates/mod.rs index db9fca5f..0dc4f239 100644 --- a/contrib/src/templates/mod.rs +++ b/contrib/src/templates/mod.rs @@ -10,13 +10,16 @@ mod handlebars_templates; #[macro_use] mod macros; +use self::serde::Serialize; +use self::glob::glob; + use std::path::{Path, PathBuf}; use std::collections::HashMap; -use self::serde::Serialize; -use rocket::response::{Content, Outcome, FreshHyperResponse, Responder}; -use rocket::{Rocket, ContentType}; -use self::glob::glob; +use rocket::Rocket; +use rocket::response::{Content, Outcome, Responder}; +use rocket::http::hyper::FreshHyperResponse; +use rocket::http::ContentType; /// The Template type implements generic support for template rendering in /// Rocket. diff --git a/examples/content_types/src/main.rs b/examples/content_types/src/main.rs index bd93563c..8e5c6893 100644 --- a/examples/content_types/src/main.rs +++ b/examples/content_types/src/main.rs @@ -4,7 +4,8 @@ extern crate rocket; extern crate serde_json; -use rocket::{Rocket, Request, Error, ContentType}; +use rocket::{Rocket, Request, Error}; +use rocket::http::ContentType; use rocket::response::data; #[derive(Debug, Serialize, Deserialize)] diff --git a/examples/cookies/src/main.rs b/examples/cookies/src/main.rs index 50ac237c..93d88171 100644 --- a/examples/cookies/src/main.rs +++ b/examples/cookies/src/main.rs @@ -8,7 +8,7 @@ extern crate tera; use rocket::Rocket; use rocket::response::Redirect; -use rocket::request::{Cookie, Cookies}; +use rocket::http::{Cookie, Cookies}; lazy_static!(static ref TERA: tera::Tera = tera::Tera::new("templates/**/*");); diff --git a/examples/manual_routes/src/main.rs b/examples/manual_routes/src/main.rs index 00420a59..d0a60bad 100644 --- a/examples/manual_routes/src/main.rs +++ b/examples/manual_routes/src/main.rs @@ -1,7 +1,7 @@ extern crate rocket; use rocket::{Rocket, Request, Response, Route}; -use rocket::Method::*; +use rocket::http::Method::*; fn root<'r>(req: &'r Request<'r>) -> Response<'r> { let name = req.get_param(0).unwrap_or("unnamed"); diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 66143877..f9388b5e 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -15,7 +15,8 @@ fn main() { #[cfg(test)] mod test { - use super::rocket::{Rocket, Request, Method}; + use super::rocket::{Rocket, Request}; + use super::rocket::http::Method; fn run_test(f: F) where F: Fn(Rocket) { let mut rocket = Rocket::new("_", 0); diff --git a/lib/Cargo.toml b/lib/Cargo.toml index b1b6b0d3..8fabb7f7 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -8,5 +8,5 @@ term-painter = "^0.2" log = "^0.3" hyper = { version = "^0.9", default-features = false } url = "^1" -mime = "^0.2" +# mime = "^0.2" toml = "^0.2" diff --git a/lib/src/catcher.rs b/lib/src/catcher.rs index d82a8280..4e47146c 100644 --- a/lib/src/catcher.rs +++ b/lib/src/catcher.rs @@ -53,13 +53,16 @@ impl fmt::Display for Catcher { } pub mod defaults { - use request::Request; - use response::{StatusCode, Response}; - use response::data; use super::Catcher; - use error::Error; + use std::collections::HashMap; + use request::Request; + use response::Response; + use response::data; + use error::Error; + use http::hyper::StatusCode; + pub fn not_found<'r>(_error: Error, _request: &'r Request<'r>) -> Response<'r> { Response::with_status(StatusCode::NotFound, data::HTML(r#" diff --git a/lib/src/codegen.rs b/lib/src/codegen.rs index a394b434..8116037b 100644 --- a/lib/src/codegen.rs +++ b/lib/src/codegen.rs @@ -1,5 +1,5 @@ -use ::{Method, Handler, ErrorHandler}; -use content_type::ContentType; +use handler::{Handler, ErrorHandler}; +use http::{Method, ContentType}; pub struct StaticRouteInfo { pub method: Method, diff --git a/lib/src/content_type.rs b/lib/src/http/content_type.rs similarity index 96% rename from lib/src/content_type.rs rename to lib/src/http/content_type.rs index 0d10c14c..6e9984cd 100644 --- a/lib/src/content_type.rs +++ b/lib/src/http/content_type.rs @@ -1,11 +1,10 @@ -pub use response::mime::{Mime, TopLevel, SubLevel}; -use response::mime::Param; use std::default::Default; use std::str::FromStr; use std::borrow::Borrow; use std::fmt; +use http::mime::{Mime, Param, TopLevel, SubLevel}; use router::Collider; /// Typed representation of HTTP Content-Types. @@ -51,8 +50,8 @@ impl ContentType { /// # Examples /// /// ```rust - /// use rocket::ContentType; - /// use rocket::response::mime::{TopLevel, SubLevel}; + /// use rocket::http::ContentType; + /// use rocket::http::mime::{TopLevel, SubLevel}; /// /// let html = ContentType::of(TopLevel::Application, SubLevel::Html); /// assert!(html.is_html()); @@ -109,7 +108,7 @@ impl ContentType { /// A recognized content type: /// /// ```rust - /// use rocket::ContentType; + /// use rocket::http::ContentType; /// /// let xml = ContentType::from_extension("xml"); /// assert!(xml.is_xml()); @@ -118,7 +117,7 @@ impl ContentType { /// An unrecognized content type: /// /// ```rust - /// use rocket::ContentType; + /// use rocket::http::ContentType; /// /// let foo = ContentType::from_extension("foo"); /// assert!(foo.is_any()); @@ -203,8 +202,8 @@ impl FromStr for ContentType { /// Parsing an `application/json`: /// /// ```rust - /// use rocket::ContentType; /// use std::str::FromStr; + /// use rocket::http::ContentType; /// /// let json = ContentType::from_str("application/json"); /// assert_eq!(json, Ok(ContentType::json())); @@ -213,9 +212,9 @@ impl FromStr for ContentType { /// Parsing a content-type extension: /// /// ```rust - /// use rocket::ContentType; /// use std::str::FromStr; - /// use rocket::response::mime::{TopLevel, SubLevel}; + /// use rocket::http::ContentType; + /// use rocket::http::mime::{TopLevel, SubLevel}; /// /// let custom = ContentType::from_str("application/x-custom").unwrap(); /// assert!(custom.is_ext()); @@ -226,8 +225,8 @@ impl FromStr for ContentType { /// Parsing an invalid Content-Type value: /// /// ```rust - /// use rocket::ContentType; /// use std::str::FromStr; + /// use rocket::http::ContentType; /// /// let custom = ContentType::from_str("application//x-custom"); /// assert!(custom.is_err()); @@ -273,7 +272,7 @@ impl fmt::Display for ContentType { /// # Example /// /// ```rust - /// use rocket::ContentType; + /// use rocket::http::ContentType; /// /// let http_ct = format!("{}", ContentType::xml()); /// assert_eq!(http_ct, "application/xml".to_string()); diff --git a/lib/src/http/cookies.rs b/lib/src/http/cookies.rs new file mode 100644 index 00000000..af84b45d --- /dev/null +++ b/lib/src/http/cookies.rs @@ -0,0 +1,4 @@ +pub use http::hyper::HyperCookiePair as Cookie; + +use http; +pub type Cookies = http::hyper::HyperCookieJar<'static>; diff --git a/lib/src/http/hyper.rs b/lib/src/http/hyper.rs new file mode 100644 index 00000000..66ace6f1 --- /dev/null +++ b/lib/src/http/hyper.rs @@ -0,0 +1,22 @@ +// TODO: Removed from Rocket in favor of a more flexible HTTP library. +pub use hyper::server::Request as HyperRequest; +pub use hyper::server::Response as HyperResponse; +pub use hyper::server::Server as HyperServer; +pub use hyper::server::Handler as HyperHandler; + +pub use hyper::header::Headers as HyperHeaders; +pub use hyper::header::CookiePair as HyperCookiePair; +pub use hyper::header::CookieJar as HyperCookieJar; +pub use hyper::header::Cookie as HyperCookie; +pub use hyper::header::SetCookie as HyperSetCookie; + +pub use hyper::method::Method as HyperMethod; +pub use hyper::uri::RequestUri as HyperRequestUri; +pub use hyper::net::Fresh as HyperFresh; +pub use hyper::header; + +// This is okay. +pub use hyper::status::StatusCode; + +// TODO: Removed from Rocket in favor of a more flexible HTTP library. +pub type FreshHyperResponse<'a> = self::HyperResponse<'a, self::HyperFresh>; diff --git a/lib/src/method.rs b/lib/src/http/method.rs similarity index 97% rename from lib/src/method.rs rename to lib/src/http/method.rs index 9f689192..effb152a 100644 --- a/lib/src/method.rs +++ b/lib/src/http/method.rs @@ -1,9 +1,9 @@ -use super::*; -use self::Method::*; - use std::fmt; use std::str::FromStr; -use hyper::method::Method as HyperMethod; + +use error::Error; +use http::hyper::HyperMethod; +use self::Method::*; #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum Method { diff --git a/lib/src/http/mod.rs b/lib/src/http/mod.rs new file mode 100644 index 00000000..cb0d1c1f --- /dev/null +++ b/lib/src/http/mod.rs @@ -0,0 +1,13 @@ +pub mod hyper; + +mod cookies; +mod method; +mod content_type; + +// TODO: Removed from Rocket in favor of a more flexible HTTP library. +pub use hyper::mime; + +pub use self::method::Method; +pub use self::hyper::StatusCode; +pub use self::content_type::ContentType; +pub use self::cookies::{Cookie, Cookies}; diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 336101b7..a8dc0480 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -58,20 +58,20 @@ //! //! Rocket is configured via the `Rocket.toml` file. //! + +#[macro_use] extern crate log; extern crate term_painter; extern crate hyper; extern crate url; -extern crate mime; +// extern crate mime; extern crate toml; -#[macro_use] extern crate log; #[doc(hidden)] #[macro_use] pub mod logger; -#[doc(hidden)] pub mod content_type; +#[doc(hidden)] pub mod http; pub mod form; pub mod request; pub mod response; -mod method; mod error; mod router; mod rocket; @@ -81,7 +81,9 @@ mod config; /// Defines the types for request and error handlers. pub mod handler { - use super::{Request, Response, Error}; + use request::Request; + use response::Response; + use error::Error; /// The type of a request handler. pub type Handler = for<'r> fn(&'r Request<'r>) -> Response<'r>; @@ -93,12 +95,10 @@ pub mod handler { #[doc(inline)] pub use response::{Response, Responder}; #[doc(inline)] pub use handler::{Handler, ErrorHandler}; #[doc(inline)] pub use logger::LoggingLevel; -pub use content_type::ContentType; pub use codegen::{StaticRouteInfo, StaticCatchInfo}; +pub use router::Route; pub use request::Request; -pub use method::Method; pub use error::Error; -pub use router::{Router, Route}; pub use catcher::Catcher; pub use rocket::Rocket; diff --git a/lib/src/request/from_request.rs b/lib/src/request/from_request.rs index 0d11c802..2f823958 100644 --- a/lib/src/request/from_request.rs +++ b/lib/src/request/from_request.rs @@ -1,7 +1,7 @@ -use request::*; -use method::Method; use std::fmt::Debug; -use content_type::ContentType; + +use request::Request; +use http::{ContentType, Method, Cookies}; pub trait FromRequest<'r, 'c>: Sized { type Error: Debug; diff --git a/lib/src/request/mod.rs b/lib/src/request/mod.rs index a024a943..b5bae776 100644 --- a/lib/src/request/mod.rs +++ b/lib/src/request/mod.rs @@ -7,12 +7,3 @@ mod from_request; pub use self::request::Request; pub use self::from_request::FromRequest; pub use self::param::{FromParam, FromSegments}; -pub use hyper::header::CookiePair as Cookie; - -// Unexported Hyper types. -#[doc(hidden)] pub use hyper::server::Request as HyperRequest; -#[doc(hidden)] pub use hyper::header::Headers as HyperHeaders; -#[doc(hidden)] pub use hyper::header::Cookie as HyperCookie; - -use hyper::header::CookieJar; -pub type Cookies = CookieJar<'static>; diff --git a/lib/src/request/request.rs b/lib/src/request/request.rs index aaafafd6..e578035c 100644 --- a/lib/src/request/request.rs +++ b/lib/src/request/request.rs @@ -7,17 +7,14 @@ use term_painter::ToStyle; use error::Error; use super::{FromParam, FromSegments}; -use method::Method; -use content_type::ContentType; -use hyper::uri::RequestUri as HyperRequestUri; use hyper::header; use router::URIBuf; use router::URI; use router::Route; -// Hyper stuff. -use request::{Cookies, HyperCookie, HyperHeaders, HyperRequest}; +use http::hyper::{HyperCookie, HyperHeaders, HyperRequest, HyperRequestUri}; +use http::{Method, ContentType, Cookies}; /// The type for all incoming web requests. /// diff --git a/lib/src/response/data.rs b/lib/src/response/data.rs index 9d154427..97d95c52 100644 --- a/lib/src/response/data.rs +++ b/lib/src/response/data.rs @@ -1,6 +1,7 @@ -use response::{header, Responder, FreshHyperResponse, Outcome}; -use response::mime::{Mime, TopLevel, SubLevel}; -use ::ContentType; +use response::{Responder, Outcome}; +use http::hyper::{header, FreshHyperResponse}; +use http::mime::{Mime, TopLevel, SubLevel}; +use http::ContentType; pub struct Content(pub ContentType, pub T); diff --git a/lib/src/response/empty.rs b/lib/src/response/empty.rs index 94af4497..79460c4c 100644 --- a/lib/src/response/empty.rs +++ b/lib/src/response/empty.rs @@ -1,6 +1,9 @@ -use response::*; use std::io::Write; +use response::{Outcome, Responder}; +use http::hyper::{header, FreshHyperResponse}; +use http::hyper::StatusCode; + pub struct Empty(StatusCode); impl Empty { diff --git a/lib/src/response/flash.rs b/lib/src/response/flash.rs index 6cab2f45..626ac881 100644 --- a/lib/src/response/flash.rs +++ b/lib/src/response/flash.rs @@ -1,7 +1,8 @@ -use response::*; use std::convert::AsRef; -use hyper::header::{SetCookie, CookiePair}; + +use response::{Outcome, Responder}; use request::{Request, FromRequest}; +use http::hyper::{HyperSetCookie, HyperCookiePair, FreshHyperResponse}; const FLASH_COOKIE_NAME: &'static str = "_flash"; @@ -32,9 +33,9 @@ impl Flash { Flash::new(responder, "error", msg) } - fn cookie_pair(&self) -> CookiePair { + fn cookie_pair(&self) -> HyperCookiePair { let content = format!("{}{}{}", self.name.len(), self.name, self.message); - let mut pair = CookiePair::new(FLASH_COOKIE_NAME.to_string(), content); + let mut pair = HyperCookiePair::new(FLASH_COOKIE_NAME.to_string(), content); pair.path = Some("/".to_string()); pair.max_age = Some(300); pair @@ -44,7 +45,7 @@ impl Flash { impl Responder for Flash { fn respond<'b>(&mut self, mut res: FreshHyperResponse<'b>) -> Outcome<'b> { trace_!("Flash: setting message: {}:{}", self.name, self.message); - res.headers_mut().set(SetCookie(vec![self.cookie_pair()])); + res.headers_mut().set(HyperSetCookie(vec![self.cookie_pair()])); self.responder.respond(res) } } diff --git a/lib/src/response/mod.rs b/lib/src/response/mod.rs index 5059694d..8689a8e9 100644 --- a/lib/src/response/mod.rs +++ b/lib/src/response/mod.rs @@ -9,11 +9,6 @@ mod stream; pub mod data; -pub use hyper::net::Fresh as HyperFresh; -pub use hyper::status::StatusCode; -pub use hyper::header; -pub use hyper::mime; - pub use self::responder::Responder; pub use self::empty::{Empty, Forward}; pub use self::redirect::Redirect; @@ -25,8 +20,7 @@ pub use self::stream::Stream; pub use self::data::Content; use std::ops::{Deref, DerefMut}; - -pub type FreshHyperResponse<'a> = ::hyper::server::Response<'a, HyperFresh>; +use http::hyper::StatusCode; pub struct Response<'a>(Box); diff --git a/lib/src/response/named_file.rs b/lib/src/response/named_file.rs index 352a9377..57301374 100644 --- a/lib/src/response/named_file.rs +++ b/lib/src/response/named_file.rs @@ -1,10 +1,12 @@ -use response::*; -use content_type::ContentType; use std::fs::File; use std::path::{Path, PathBuf}; use std::io; use std::ops::{Deref, DerefMut}; +use response::{Responder, Outcome}; +use http::hyper::{header, FreshHyperResponse}; +use http::ContentType; + #[derive(Debug)] pub struct NamedFile(PathBuf, File); diff --git a/lib/src/response/outcome.rs b/lib/src/response/outcome.rs index 9dc15bee..4bfb2c15 100644 --- a/lib/src/response/outcome.rs +++ b/lib/src/response/outcome.rs @@ -1,8 +1,9 @@ -use response::*; +use std::fmt; use term_painter::Color::*; use term_painter::ToStyle; -use std::fmt; + +use http::hyper::FreshHyperResponse; pub enum Outcome<'h> { /// Signifies a response that completed sucessfully. diff --git a/lib/src/response/redirect.rs b/lib/src/response/redirect.rs index f0cad55b..1e20493f 100644 --- a/lib/src/response/redirect.rs +++ b/lib/src/response/redirect.rs @@ -1,4 +1,5 @@ -use response::*; +use response::{Outcome, Responder}; +use http::hyper::{header, FreshHyperResponse, StatusCode}; #[derive(Debug)] pub struct Redirect(StatusCode, String); diff --git a/lib/src/response/responder.rs b/lib/src/response/responder.rs index 41e22ea5..06d09740 100644 --- a/lib/src/response/responder.rs +++ b/lib/src/response/responder.rs @@ -1,9 +1,11 @@ -use response::*; -use response::mime::{Mime, TopLevel, SubLevel}; use std::io::{Read, Write}; use std::fs::File; use std::fmt; +use response::Outcome; +use http::mime::{Mime, TopLevel, SubLevel}; +use http::hyper::{header, FreshHyperResponse, StatusCode}; + // TODO: Have this return something saying whether every was okay. Need // something like to be able to forward requests on when things don't work out. // In particular, we want to try the next ranked route when when parsing diff --git a/lib/src/response/stream.rs b/lib/src/response/stream.rs index 86e1790d..c8796d74 100644 --- a/lib/src/response/stream.rs +++ b/lib/src/response/stream.rs @@ -1,6 +1,8 @@ -use response::*; use std::io::{Read, Write, ErrorKind}; +use response::{Responder, Outcome}; +use http::hyper::FreshHyperResponse; + // TODO: Support custom chunk sizes. /// The default size of each chunk in the streamed response. pub const CHUNK_SIZE: usize = 4096; diff --git a/lib/src/response/with_status.rs b/lib/src/response/with_status.rs index be230eac..eb08292c 100644 --- a/lib/src/response/with_status.rs +++ b/lib/src/response/with_status.rs @@ -1,4 +1,5 @@ -use response::*; +use response::{Responder, Outcome}; +use http::hyper::{StatusCode, FreshHyperResponse}; pub struct StatusResponse { status: StatusCode, diff --git a/lib/src/rocket.rs b/lib/src/rocket.rs index eaa80b74..e9027def 100644 --- a/lib/src/rocket.rs +++ b/lib/src/rocket.rs @@ -1,9 +1,3 @@ -use super::*; -use response::{FreshHyperResponse, Outcome}; -use request::HyperRequest; -use catcher; -use config::RocketConfig; - use std::collections::HashMap; use std::str::from_utf8_unchecked; use std::cmp::min; @@ -12,9 +6,18 @@ use std::process; use term_painter::Color::*; use term_painter::ToStyle; -use hyper::server::Server as HyperServer; -use hyper::server::Handler as HyperHandler; -use hyper::header::SetCookie; +use logger::{self, LoggingLevel}; +use request::Request; +use router::{Router, Route}; +use catcher::{self, Catcher}; +use response::Outcome; +use config::RocketConfig; +use form::FormItems; +use error::Error; + +use http::Method; +use http::hyper::{HyperRequest, FreshHyperResponse}; +use http::hyper::{HyperServer, HyperHandler, HyperSetCookie, header}; pub struct Rocket { address: String, @@ -28,7 +31,7 @@ impl HyperHandler for Rocket { fn handle<'h, 'k>(&self, req: HyperRequest<'h, 'k>, mut res: FreshHyperResponse<'h>) { - res.headers_mut().set(response::header::Server("rocket".to_string())); + res.headers_mut().set(header::Server("rocket".to_string())); self.dispatch(req, res) } } @@ -64,7 +67,7 @@ impl Rocket { let mut responder = (route.handler)(&request); let cookie_delta = request.cookies().delta(); if cookie_delta.len() > 0 { - res.headers_mut().set(SetCookie(cookie_delta)); + res.headers_mut().set(HyperSetCookie(cookie_delta)); } // Get the response. @@ -95,7 +98,7 @@ impl Rocket { from_utf8_unchecked(&req.data.as_slice()[..min(data_len, max_len)]) }; - let mut form_items = form::FormItems(form); + let mut form_items = FormItems(form); if let Some(("_method", value)) = form_items.next() { if let Ok(method) = value.parse() { req.method = method; diff --git a/lib/src/router/collider.rs b/lib/src/router/collider.rs index 3b67bc0f..1bc068fe 100644 --- a/lib/src/router/collider.rs +++ b/lib/src/router/collider.rs @@ -46,14 +46,15 @@ impl<'a> Collider for &'a str { #[cfg(test)] mod tests { - use router::Collider; - use router::route::Route; - use Method; - use Method::*; - use {Request, Response}; - use content_type::ContentType; use std::str::FromStr; - use router::URI; + + use router::{Collider, URI}; + use request::Request; + use response::Response; + use router::route::Route; + use http::{Method, ContentType}; + + use http::Method::*; type SimpleRoute = (Method, &'static str); diff --git a/lib/src/router/mod.rs b/lib/src/router/mod.rs index 93d2db0f..422ec59f 100644 --- a/lib/src/router/mod.rs +++ b/lib/src/router/mod.rs @@ -7,7 +7,8 @@ pub use self::uri::{URI, URIBuf, Segments}; pub use self::route::Route; use std::collections::hash_map::HashMap; -use method::Method; + +use http::Method; use request::Request; // type Selector = (Method, usize); @@ -68,11 +69,11 @@ impl Router { #[cfg(test)] mod test { - use method::Method; - use method::Method::*; - use super::{Router, Route}; + use super::{Router, Route, URI}; + + use http::Method; + use http::Method::*; use {Response, Request}; - use super::URI; fn dummy_handler(_req: &Request) -> Response<'static> { Response::empty() diff --git a/lib/src/router/route.rs b/lib/src/router/route.rs index 426733f0..48bed2f9 100644 --- a/lib/src/router/route.rs +++ b/lib/src/router/route.rs @@ -1,13 +1,15 @@ -use ::{Method, Handler, StaticRouteInfo}; -use content_type::ContentType; -use super::{Collider, URI, URIBuf}; // :D +use std::fmt; +use std::convert::From; use term_painter::ToStyle; use term_painter::Color::*; -use std::fmt; -use std::convert::From; +use super::{Collider, URI, URIBuf}; // :D + +use codegen::StaticRouteInfo; +use handler::Handler; use request::Request; +use http::{Method, ContentType}; pub struct Route { pub method: Method,