diff --git a/.gitignore b/.gitignore index 4fffb2f89c..2c96eb1b65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target -/Cargo.lock +target/ +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 4f009fdf6c..3e4d928515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hyper" -version = "0.0.15" +version = "0.1.0" description = "A modern HTTP library." readme = "README.md" documentation = "http://hyperium.github.io/hyper/hyper/index.html" @@ -10,16 +10,36 @@ license = "MIT" authors = ["Sean McArthur ", "Jonathan Reem "] -[dependencies] -url = "*" -openssl = "*" -mime = "*" -unsafe-any = "*" -typeable = "*" -cookie = "*" -time = "*" -mucell = "*" +[dependencies.hyper-core] +path = "src/core/" +version = "0.1.0" +[dependencies.hyper-protocol] +path = "src/protocol/" +version = "0.1.0" +[dependencies.hyper-net] +path = "src/net/" +optional = true +version = "0.1.0" +[dependencies.hyper-client] +path = "src/client/" +optional = true +version = "0.1.0" +[dependencies.hyper-server] +path = "src/server/" +optional = true +version = "0.1.0" +[features] +default = [ "hyper-client", "hyper-server" , "hyper-net" ] +net = [ "hyper-net" ] +server = [ "hyper-server", "hyper-net" ] +client = [ "hyper-client", "hyper-net" ] +[dependencies.url] +version = "*" +[dependencies.mime] +version = "*" -[dev-dependencies] -curl = "*" +[dev-dependencies.curl] +version = "*" +[dev-dependencies.http] +version = "*" diff --git a/publish-all.sh b/publish-all.sh new file mode 100644 index 0000000000..7d50db73b3 --- /dev/null +++ b/publish-all.sh @@ -0,0 +1,11 @@ +#/bin/sh + +# If the versions haven't changed, this'll just error, but we'll just keep chugging. +# That's fine. That said, just bump the version numbers when you'd like to publish. + +cargo publish --manifest-path src/core; +cargo publish --manifest-path src/protocol; +cargo publish --manifest-path src/net; +cargo publish --manifest-path src/client; +cargo publish --manifest-path src/server; +cargo publish --manifest-path .; diff --git a/src/client/Cargo.toml b/src/client/Cargo.toml new file mode 100644 index 0000000000..e3e66d9bfa --- /dev/null +++ b/src/client/Cargo.toml @@ -0,0 +1,22 @@ +[package] + +name = "hyper-client" +version = "0.1.0" +authors = ["Sean McArthur "] + +[dependencies.hyper-core] +path = "../core" +version = "0.1.0" +[dependencies.hyper-protocol] +path = "../protocol" +version = "0.1.0" +[dependencies.hyper-net] +path = "../net" +version = "0.1.0" + +[dependencies.time] +version = "*" +[dependencies.url] +version = "*" +[dependencies.openssl] +version = "*" diff --git a/src/client/mod.rs b/src/client/src/lib.rs similarity index 94% rename from src/client/mod.rs rename to src/client/src/lib.rs index 57e2788347..3f89a8284d 100644 --- a/src/client/mod.rs +++ b/src/client/src/lib.rs @@ -17,23 +17,35 @@ //! The returned value from is a `Response`, which provides easy access //! to the `status`, the `headers`, and the response body via the `Writer` //! trait. +#![feature(slicing_syntax, default_type_params, phase)] + +#[phase(link, plugin)] +extern crate log; +extern crate "hyper-net" as net; +extern crate "hyper-protocol" as header; +#[phase(link, plugin)] +extern crate "hyper-core" as hc; +extern crate url; +extern crate openssl; + use std::default::Default; use std::io::IoResult; use std::io::util::copy; use std::iter::Extend; -use url::UrlParser; +use url::{Url, UrlParser}; use url::ParseError as UrlError; use openssl::ssl::VerifyCallback; use header::{Headers, Header, HeaderFormat}; use header::common::{ContentLength, Location}; -use method::Method; +use hc::method::Method; use net::{NetworkConnector, NetworkStream, HttpConnector}; -use status::StatusClass::Redirection; -use {Url, Port, HttpResult}; -use HttpError::HttpUriError; +use hc::status::StatusClass::Redirection; +use header::Port; +use hc::HttpResult; +use hc::HttpError::HttpUriError; pub use self::request::Request; pub use self::response::Response; @@ -404,3 +416,10 @@ mod tests { } } + +//FIXME: when Opt-in Built-in Types becomes a thing, we can force these structs +//to be Send. For now, this has the compiler do a static check. +fn _assert_send() { + _assert_send::>(); + _assert_send::(); +} diff --git a/src/client/request.rs b/src/client/src/request.rs similarity index 96% rename from src/client/request.rs rename to src/client/src/request.rs index 6787e86bf8..74182d983b 100644 --- a/src/client/request.rs +++ b/src/client/src/request.rs @@ -3,16 +3,16 @@ use std::io::{BufferedWriter, IoResult}; use url::Url; -use method; -use method::Method::{Get, Post, Delete, Put, Patch, Head, Options}; +use hc::method; +use hc::method::Method::{Get, Post, Delete, Put, Patch, Head, Options}; use header::Headers; use header::common::{mod, Host}; use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming}; -use http::{HttpWriter, LINE_ENDING}; -use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter}; -use version; -use HttpResult; -use client::{Response, get_host_and_port}; +use hc::http::{HttpWriter, LINE_ENDING}; +use hc::http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter}; +use hc::version; +use hc::HttpResult; +use {Response, get_host_and_port}; /// A client request to a remote server. diff --git a/src/client/response.rs b/src/client/src/response.rs similarity index 94% rename from src/client/response.rs rename to src/client/src/response.rs index 7bffe22df2..a8f4120a45 100644 --- a/src/client/response.rs +++ b/src/client/src/response.rs @@ -6,12 +6,12 @@ use header; use header::common::{ContentLength, TransferEncoding}; use header::common::transfer_encoding::Encoding::Chunked; use net::{NetworkStream, HttpStream}; -use http::{read_status_line, HttpReader, RawStatus}; -use http::HttpReader::{SizedReader, ChunkedReader, EofReader}; -use status; -use version; -use HttpResult; -use HttpError::HttpStatusError; +use hc::http::{read_status_line, HttpReader, RawStatus}; +use hc::http::HttpReader::{SizedReader, ChunkedReader, EofReader}; +use hc::status; +use hc::version; +use hc::HttpResult; +use hc::HttpError::HttpStatusError; /// A response for a client request to a remote server. pub struct Response { diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml new file mode 100644 index 0000000000..1ff7441816 --- /dev/null +++ b/src/core/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hyper-core" +version = "0.1.0" +authors = [ "Sean McArthur " ] + +[dependencies.url] +version = "*" diff --git a/src/http.rs b/src/core/src/http.rs similarity index 99% rename from src/http.rs rename to src/core/src/http.rs index b02a09a11b..570b3a5df8 100644 --- a/src/http.rs +++ b/src/core/src/http.rs @@ -588,7 +588,7 @@ pub struct RawStatus(pub u16, pub SendStr); impl Clone for RawStatus { fn clone(&self) -> RawStatus { - RawStatus(self.0, self.1.clone().into_cow()) + RawStatus(self.0, (*self.1).into_string().into_cow()) } } diff --git a/src/core/src/lib.rs b/src/core/src/lib.rs new file mode 100644 index 0000000000..f0755fa486 --- /dev/null +++ b/src/core/src/lib.rs @@ -0,0 +1,98 @@ +#![feature(slicing_syntax, phase, macro_rules)] + +extern crate url; +#[phase(plugin, link)] extern crate log; + +use std::fmt; +use std::error::{Error, FromError}; +use std::io::IoError; +use std::rt::backtrace; +use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError, + HttpHeaderError, HttpStatusError, HttpIoError}; + +#[macro_export] macro_rules! todo( + ($($arg:tt)*) => (if cfg!(not(ndebug)) { + format_args!(|args| log!(5, "TODO: {}", args), $($arg)*) + }) +); +#[macro_export] macro_rules! trace( + ($($arg:tt)*) => (if cfg!(not(ndebug)) { + format_args!(|args| log!(5, "{}\n{}", args, ::Trace), $($arg)*) + }) +); + +#[macro_export] macro_rules! inspect( + ($name:expr, $value:expr) => ({ + let v = $value; + debug!("inspect: {} = {}", $name, v); + v + }) +); + +pub mod http; +pub mod method; +pub mod version; +pub mod status; +pub mod uri; + +#[allow(dead_code)] +struct Trace; + +impl fmt::Show for Trace { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + let _ = backtrace::write(fmt); + Result::Ok(()) + } +} + +/// Result type often returned from methods that can have `HttpError`s. +pub type HttpResult = Result; +/// A set of errors that can occur parsing HTTP streams. +#[deriving(Show, PartialEq, Clone)] +pub enum HttpError { + /// An invalid `Method`, such as `GE,T`. + HttpMethodError, + /// An invalid `RequestUri`, such as `exam ple.domain`. + HttpUriError(url::ParseError), + /// An invalid `HttpVersion`, such as `HTP/1.1` + HttpVersionError, + /// An invalid `Header`. + HttpHeaderError, + /// An invalid `Status`, such as `1337 ELITE`. + HttpStatusError, + /// An `IoError` that occured while trying to read or write to a network stream. + HttpIoError(IoError), +} + +impl Error for HttpError { + fn description(&self) -> &str { + match *self { + HttpMethodError => "Invalid Method specified", + HttpUriError(_) => "Invalid Request URI specified", + HttpVersionError => "Invalid HTTP version specified", + HttpHeaderError => "Invalid Header provided", + HttpStatusError => "Invalid Status provided", + HttpIoError(_) => "An IoError occurred while connecting to the specified network", + } + } + + fn cause(&self) -> Option<&Error> { + match *self { + HttpIoError(ref error) => Some(error as &Error), + HttpUriError(ref error) => Some(error as &Error), + _ => None, + } + } +} + +impl FromError for HttpError { + fn from_error(err: IoError) -> HttpError { + HttpIoError(err) + } +} + +impl FromError for HttpError { + fn from_error(err: url::ParseError) -> HttpError { + HttpUriError(err) + } +} diff --git a/src/method.rs b/src/core/src/method.rs similarity index 100% rename from src/method.rs rename to src/core/src/method.rs diff --git a/src/status.rs b/src/core/src/status.rs similarity index 100% rename from src/status.rs rename to src/core/src/status.rs diff --git a/src/uri.rs b/src/core/src/uri.rs similarity index 100% rename from src/uri.rs rename to src/core/src/uri.rs diff --git a/src/version.rs b/src/core/src/version.rs similarity index 100% rename from src/version.rs rename to src/core/src/version.rs diff --git a/src/lib.rs b/src/lib.rs index 3e199ce6e0..2c317ccf9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,140 +125,48 @@ //! implement `Reader` and can be read to get the data out of a `Response`. //! -extern crate serialize; -extern crate time; extern crate url; -extern crate openssl; -#[phase(plugin,link)] extern crate log; -#[cfg(test)] extern crate test; -extern crate "unsafe-any" as uany; -extern crate cookie; -extern crate mucell; pub use std::io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port}; pub use mimewrapper::mime; pub use url::Url; -pub use client::Client; -pub use method::Method::{Get, Head, Post, Delete}; -pub use status::StatusCode::{Ok, BadRequest, NotFound}; -pub use server::Server; -use std::fmt; -use std::error::{Error, FromError}; -use std::io::IoError; +#[cfg(feature = "hyper-client")] +pub use import_wrapper::client::Client; +#[cfg(feature = "hyper-client")] +pub use import_wrapper::client; +#[cfg(feature = "hyper-server")] +pub use import_wrapper::server::Server; +#[cfg(feature = "hyper-server")] +pub use import_wrapper::server; +#[cfg(feature = "hyper-net")] +pub use import_wrapper::net; -use std::rt::backtrace; +pub use import_wrapper::protocol; -use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError, - HttpHeaderError, HttpStatusError, HttpIoError}; - -macro_rules! todo( - ($($arg:tt)*) => (if cfg!(not(ndebug)) { - format_args!(|args| log!(5, "TODO: {}", args), $($arg)*) - }) -); - -#[allow(dead_code)] -struct Trace; - -impl fmt::Show for Trace { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let _ = backtrace::write(fmt); - Result::Ok(()) - } -} - -macro_rules! trace( - ($($arg:tt)*) => (if cfg!(not(ndebug)) { - format_args!(|args| log!(5, "{}\n{}", args, ::Trace), $($arg)*) - }) -); - -macro_rules! inspect( - ($name:expr, $value:expr) => ({ - let v = $value; - debug!("inspect: {} = {}", $name, v); - v - }) -); +pub use import_wrapper::core; +pub use import_wrapper::core::method::Method::{Get, Head, Post, Delete}; +pub use import_wrapper::core::status::StatusCode::{Ok, BadRequest, NotFound}; +pub use import_wrapper::core::{HttpResult, HttpError}; #[cfg(test)] #[macro_escape] mod mock; -pub mod client; -pub mod method; -pub mod header; -pub mod http; -pub mod net; -pub mod server; -pub mod status; -pub mod uri; -pub mod version; +mod import_wrapper { + extern crate "hyper-core" as core; + extern crate "hyper-protocol" as protocol; + + #[cfg(feature = "hyper-net")] + extern crate "hyper-net" as net; + #[cfg(feature = "hyper-server")] + extern crate "hyper-server" as server; + #[cfg(feature = "hyper-client")] + extern crate "hyper-client" as client; +} mod mimewrapper { /// Re-exporting the mime crate, for convenience. extern crate mime; } - - -/// Result type often returned from methods that can have `HttpError`s. -pub type HttpResult = Result; - -/// A set of errors that can occur parsing HTTP streams. -#[deriving(Show, PartialEq, Clone)] -pub enum HttpError { - /// An invalid `Method`, such as `GE,T`. - HttpMethodError, - /// An invalid `RequestUri`, such as `exam ple.domain`. - HttpUriError(url::ParseError), - /// An invalid `HttpVersion`, such as `HTP/1.1` - HttpVersionError, - /// An invalid `Header`. - HttpHeaderError, - /// An invalid `Status`, such as `1337 ELITE`. - HttpStatusError, - /// An `IoError` that occured while trying to read or write to a network stream. - HttpIoError(IoError), -} - -impl Error for HttpError { - fn description(&self) -> &str { - match *self { - HttpMethodError => "Invalid Method specified", - HttpUriError(_) => "Invalid Request URI specified", - HttpVersionError => "Invalid HTTP version specified", - HttpHeaderError => "Invalid Header provided", - HttpStatusError => "Invalid Status provided", - HttpIoError(_) => "An IoError occurred while connecting to the specified network", - } - } - - fn cause(&self) -> Option<&Error> { - match *self { - HttpIoError(ref error) => Some(error as &Error), - HttpUriError(ref error) => Some(error as &Error), - _ => None, - } - } -} - -impl FromError for HttpError { - fn from_error(err: IoError) -> HttpError { - HttpIoError(err) - } -} - -impl FromError for HttpError { - fn from_error(err: url::ParseError) -> HttpError { - HttpUriError(err) - } -} - -//FIXME: when Opt-in Built-in Types becomes a thing, we can force these structs -//to be Send. For now, this has the compiler do a static check. -fn _assert_send() { - _assert_send::>(); - _assert_send::(); -} diff --git a/src/net/Cargo.toml b/src/net/Cargo.toml new file mode 100644 index 0000000000..ac4ddf14a0 --- /dev/null +++ b/src/net/Cargo.toml @@ -0,0 +1,15 @@ +[package] + +name = "hyper-net" +version = "0.1.0" +authors = ["Sean McArthur "] + +[dependencies.hyper-core] +path = "../core" +version = "0.1.0" + +[dependencies.openssl] +version = "*" +[dependencies.unsafe-any] +version = "*" + diff --git a/src/net.rs b/src/net/src/lib.rs similarity index 98% rename from src/net.rs rename to src/net/src/lib.rs index c5fabf0c21..366d3e0559 100644 --- a/src/net.rs +++ b/src/net/src/lib.rs @@ -1,4 +1,11 @@ //! A collection of traits abstracting over Listeners and Streams. +#![feature(phase)] + +#[phase(link, plugin)] +extern crate log; +extern crate "unsafe-any" as uany; +extern crate openssl; + use std::any::{Any, AnyRefExt}; use std::boxed::BoxAny; use std::fmt; diff --git a/src/protocol/Cargo.toml b/src/protocol/Cargo.toml new file mode 100644 index 0000000000..8a28827904 --- /dev/null +++ b/src/protocol/Cargo.toml @@ -0,0 +1,21 @@ +[package] + +name = "hyper-protocol" +version = "0.1.0" +authors = ["Sean McArthur "] + +[dependencies.hyper-core] +path = "../core/" +version = "0.1.0" + + +[dependencies.mucell] +version = "*" +[dependencies.unsafe-any] +version = "*" +[dependencies.time] +version = "*" +[dependencies.mime] +version = "*" +[dependencies.cookie] +version = "*" diff --git a/src/header/common/accept.rs b/src/protocol/src/common/accept.rs similarity index 98% rename from src/header/common/accept.rs rename to src/protocol/src/common/accept.rs index 3080ebbd9d..1bdf853405 100644 --- a/src/header/common/accept.rs +++ b/src/protocol/src/common/accept.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use std::str::from_utf8; use mime::Mime; diff --git a/src/header/common/allow.rs b/src/protocol/src/common/allow.rs similarity index 96% rename from src/header/common/allow.rs rename to src/protocol/src/common/allow.rs index 07e17cd2fd..b299d63ecf 100644 --- a/src/header/common/allow.rs +++ b/src/protocol/src/common/allow.rs @@ -1,5 +1,5 @@ -use header::{Header, HeaderFormat}; -use method::Method; +use {Header, HeaderFormat}; +use hc::method::Method; use std::fmt::{mod}; use super::util::{from_comma_delimited, fmt_comma_delimited}; diff --git a/src/header/common/authorization.rs b/src/protocol/src/common/authorization.rs similarity index 99% rename from src/header/common/authorization.rs rename to src/protocol/src/common/authorization.rs index b6708b951f..3addfe6c0f 100644 --- a/src/header/common/authorization.rs +++ b/src/protocol/src/common/authorization.rs @@ -1,7 +1,7 @@ use std::fmt::{mod, Show}; use std::str::{FromStr, from_utf8}; use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline}; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; /// The `Authorization` header field. #[deriving(Clone, PartialEq, Show)] diff --git a/src/header/common/cache_control.rs b/src/protocol/src/common/cache_control.rs similarity index 99% rename from src/header/common/cache_control.rs rename to src/protocol/src/common/cache_control.rs index 1844c82b2e..ea2dc321ac 100644 --- a/src/header/common/cache_control.rs +++ b/src/protocol/src/common/cache_control.rs @@ -1,6 +1,6 @@ use std::fmt; use std::str::FromStr; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::{from_one_comma_delimited, fmt_comma_delimited}; /// The Cache-Control header. diff --git a/src/header/common/connection.rs b/src/protocol/src/common/connection.rs similarity index 98% rename from src/header/common/connection.rs rename to src/protocol/src/common/connection.rs index 2ae9b97207..be8b7a8a98 100644 --- a/src/header/common/connection.rs +++ b/src/protocol/src/common/connection.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use std::str::FromStr; use super::util::{from_comma_delimited, fmt_comma_delimited}; diff --git a/src/header/common/content_length.rs b/src/protocol/src/common/content_length.rs similarity index 96% rename from src/header/common/content_length.rs rename to src/protocol/src/common/content_length.rs index 32957b9754..e32d4ba7a0 100644 --- a/src/header/common/content_length.rs +++ b/src/protocol/src/common/content_length.rs @@ -1,6 +1,6 @@ use std::fmt::{mod, Show}; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::from_one_raw_str; /// The `Content-Length` header. diff --git a/src/header/common/content_type.rs b/src/protocol/src/common/content_type.rs similarity index 95% rename from src/header/common/content_type.rs rename to src/protocol/src/common/content_type.rs index 4b26dac59d..bbd22d8e7a 100644 --- a/src/header/common/content_type.rs +++ b/src/protocol/src/common/content_type.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use super::util::from_one_raw_str; use mime::Mime; diff --git a/src/header/common/cookie.rs b/src/protocol/src/common/cookie.rs similarity index 98% rename from src/header/common/cookie.rs rename to src/protocol/src/common/cookie.rs index a47179956e..4cb84bee7c 100644 --- a/src/header/common/cookie.rs +++ b/src/protocol/src/common/cookie.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use std::str::{from_utf8, from_str}; diff --git a/src/header/common/date.rs b/src/protocol/src/common/date.rs similarity index 96% rename from src/header/common/date.rs rename to src/protocol/src/common/date.rs index a33d16a44e..162a67ffd3 100644 --- a/src/header/common/date.rs +++ b/src/protocol/src/common/date.rs @@ -1,7 +1,7 @@ use std::fmt::{mod, Show}; use std::str::FromStr; use time::Tm; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::{from_one_raw_str, tm_from_str}; // Egh, replace as soon as something better than time::Tm exists. diff --git a/src/header/common/etag.rs b/src/protocol/src/common/etag.rs similarity index 99% rename from src/header/common/etag.rs rename to src/protocol/src/common/etag.rs index 74a355d3eb..4166a5145f 100644 --- a/src/header/common/etag.rs +++ b/src/protocol/src/common/etag.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod}; use super::util::from_one_raw_str; diff --git a/src/header/common/expires.rs b/src/protocol/src/common/expires.rs similarity index 96% rename from src/header/common/expires.rs rename to src/protocol/src/common/expires.rs index f9dfe35c2f..28aa19541a 100644 --- a/src/header/common/expires.rs +++ b/src/protocol/src/common/expires.rs @@ -1,7 +1,7 @@ use std::fmt::{mod, Show}; use std::str::FromStr; use time::Tm; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::{from_one_raw_str, tm_from_str}; /// The `Expires` header field. diff --git a/src/header/common/host.rs b/src/protocol/src/common/host.rs similarity index 98% rename from src/header/common/host.rs rename to src/protocol/src/common/host.rs index dd1554e9e3..e20b2bb786 100644 --- a/src/header/common/host.rs +++ b/src/protocol/src/common/host.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use Port; use std::fmt::{mod, Show}; use super::util::from_one_raw_str; diff --git a/src/header/common/if_modified_since.rs b/src/protocol/src/common/if_modified_since.rs similarity index 97% rename from src/header/common/if_modified_since.rs rename to src/protocol/src/common/if_modified_since.rs index 850e3dff1d..43317d2428 100644 --- a/src/header/common/if_modified_since.rs +++ b/src/protocol/src/common/if_modified_since.rs @@ -1,7 +1,7 @@ use std::fmt::{mod, Show}; use std::str::FromStr; use time::Tm; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::{from_one_raw_str, tm_from_str}; /// The `If-Modified-Since` header field. diff --git a/src/header/common/last_modified.rs b/src/protocol/src/common/last_modified.rs similarity index 96% rename from src/header/common/last_modified.rs rename to src/protocol/src/common/last_modified.rs index 5606f093b5..94196bc9f2 100644 --- a/src/header/common/last_modified.rs +++ b/src/protocol/src/common/last_modified.rs @@ -1,7 +1,7 @@ use std::fmt::{mod, Show}; use std::str::FromStr; use time::Tm; -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use super::util::{from_one_raw_str, tm_from_str}; /// The `LastModified` header field. diff --git a/src/header/common/location.rs b/src/protocol/src/common/location.rs similarity index 97% rename from src/header/common/location.rs rename to src/protocol/src/common/location.rs index ea3b815dfd..a704bb50e2 100644 --- a/src/header/common/location.rs +++ b/src/protocol/src/common/location.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use super::util::from_one_raw_str; diff --git a/src/header/common/mod.rs b/src/protocol/src/common/mod.rs similarity index 100% rename from src/header/common/mod.rs rename to src/protocol/src/common/mod.rs diff --git a/src/header/common/server.rs b/src/protocol/src/common/server.rs similarity index 95% rename from src/header/common/server.rs rename to src/protocol/src/common/server.rs index 64c3ca1dc3..b7d5b7c6bb 100644 --- a/src/header/common/server.rs +++ b/src/protocol/src/common/server.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use super::util::from_one_raw_str; diff --git a/src/header/common/set_cookie.rs b/src/protocol/src/common/set_cookie.rs similarity index 98% rename from src/header/common/set_cookie.rs rename to src/protocol/src/common/set_cookie.rs index aee732d1f8..e2c67c324b 100644 --- a/src/header/common/set_cookie.rs +++ b/src/protocol/src/common/set_cookie.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use std::str::from_utf8; diff --git a/src/header/common/transfer_encoding.rs b/src/protocol/src/common/transfer_encoding.rs similarity index 98% rename from src/header/common/transfer_encoding.rs rename to src/protocol/src/common/transfer_encoding.rs index e0572cf011..d4b1947b75 100644 --- a/src/header/common/transfer_encoding.rs +++ b/src/protocol/src/common/transfer_encoding.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt; use std::str::FromStr; use super::util::{from_comma_delimited, fmt_comma_delimited}; diff --git a/src/header/common/upgrade.rs b/src/protocol/src/common/upgrade.rs similarity index 97% rename from src/header/common/upgrade.rs rename to src/protocol/src/common/upgrade.rs index 296478b868..818fe531da 100644 --- a/src/header/common/upgrade.rs +++ b/src/protocol/src/common/upgrade.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use std::str::FromStr; use super::util::{from_comma_delimited, fmt_comma_delimited}; diff --git a/src/header/common/user_agent.rs b/src/protocol/src/common/user_agent.rs similarity index 95% rename from src/header/common/user_agent.rs rename to src/protocol/src/common/user_agent.rs index f35e7cbdc3..f890c43477 100644 --- a/src/header/common/user_agent.rs +++ b/src/protocol/src/common/user_agent.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat}; +use {Header, HeaderFormat}; use std::fmt::{mod, Show}; use super::util::from_one_raw_str; diff --git a/src/header/common/util.rs b/src/protocol/src/common/util.rs similarity index 100% rename from src/header/common/util.rs rename to src/protocol/src/common/util.rs diff --git a/src/header/common/vary.rs b/src/protocol/src/common/vary.rs similarity index 97% rename from src/header/common/vary.rs rename to src/protocol/src/common/vary.rs index 9b54818965..c69bd78047 100644 --- a/src/header/common/vary.rs +++ b/src/protocol/src/common/vary.rs @@ -1,4 +1,4 @@ -use header::{Header, HeaderFormat, CaseInsensitive}; +use {Header, HeaderFormat, CaseInsensitive}; use std::fmt::{mod}; use super::util::{from_comma_delimited, fmt_comma_delimited, from_one_raw_str}; diff --git a/src/header/mod.rs b/src/protocol/src/lib.rs similarity index 97% rename from src/header/mod.rs rename to src/protocol/src/lib.rs index 01cb3f80ee..bd2863f4f9 100644 --- a/src/header/mod.rs +++ b/src/protocol/src/lib.rs @@ -4,6 +4,20 @@ //! why we're using Rust in the first place. To set or get any header, an object //! must implement the `Header` trait from this module. Several common headers //! are already provided, such as `Host`, `ContentType`, `UserAgent`, and others. + +#![feature(slicing_syntax, phase, macro_rules, globs, default_type_params)] + +#[phase(link, plugin)] extern crate log; +extern crate "unsafe-any" as uany; +extern crate mucell; +extern crate "hyper-core" as hc; +extern crate time; +extern crate serialize; +extern crate cookie; +extern crate mime; + +pub use std::io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port}; + use std::any::Any; use std::ascii::{AsciiExt, AsciiCast}; use std::borrow::Cow::{Borrowed, Owned}; @@ -18,10 +32,12 @@ use std::{hash, mem}; use mucell::MuCell; use uany::{UncheckedAnyDowncast, UncheckedAnyMutDowncast}; -use http::{mod, LineEnding}; -use {HttpResult}; +use hc::http::{mod, LineEnding}; +use hc::{HttpResult}; -pub use self::common::*; +pub mod headers { + pub use super::common::*; +} /// Common Headers pub mod common; @@ -458,7 +474,7 @@ impl FromStr for CaseInsensitive { impl Clone for CaseInsensitive { fn clone(&self) -> CaseInsensitive { - CaseInsensitive(self.0.clone().into_cow()) + CaseInsensitive((*self.0).into_string().into_cow()) } } diff --git a/src/server/Cargo.toml b/src/server/Cargo.toml new file mode 100644 index 0000000000..0453d4a187 --- /dev/null +++ b/src/server/Cargo.toml @@ -0,0 +1,18 @@ +[package] + +name = "hyper-server" +version = "0.1.0" +authors = ["Sean McArthur "] + +[dependencies.hyper-core] +path = "../core" +version = "0.1.0" +[dependencies.hyper-protocol] +path = "../protocol" +version = "0.1.0" +[dependencies.hyper-net] +path = "../net" +version = "0.1.0" + +[dependencies.time] +version = "*" diff --git a/src/server/mod.rs b/src/server/src/lib.rs similarity index 93% rename from src/server/mod.rs rename to src/server/src/lib.rs index 29ff0bdfd8..22a885f97d 100644 --- a/src/server/mod.rs +++ b/src/server/src/lib.rs @@ -1,23 +1,33 @@ //! HTTP Server + +#![feature(default_type_params, macro_rules, phase)] + +#[phase(link, plugin)] +extern crate log; +#[phase(link, plugin)] +extern crate "hyper-core" as hc; +extern crate "hyper-protocol" as header; +extern crate time; +extern crate "hyper-net" as net; + use std::io::{Listener, EndOfFile, BufferedReader, BufferedWriter}; use std::io::net::ip::{IpAddr, Port, SocketAddr}; use std::os; use std::sync::{Arc, TaskPool}; use std::thread::Builder; - pub use self::request::Request; pub use self::response::Response; pub use net::{Fresh, Streaming}; -use HttpError::HttpIoError; -use {HttpResult}; -use header::common::Connection; -use header::common::connection::{KeepAlive, Close}; +use hc::HttpError::HttpIoError; +use hc::{HttpResult}; +use header::headers::Connection; +use header::headers::connection::{KeepAlive, Close}; use net::{NetworkListener, NetworkAcceptor, NetworkStream, HttpAcceptor, HttpListener, HttpStream}; -use version::HttpVersion::{Http10, Http11}; +use hc::version::HttpVersion::{Http10, Http11}; pub mod request; pub mod response; diff --git a/src/server/request.rs b/src/server/src/request.rs similarity index 93% rename from src/server/request.rs rename to src/server/src/request.rs index b35efcc5ff..b1d72b25f3 100644 --- a/src/server/request.rs +++ b/src/server/src/request.rs @@ -5,15 +5,15 @@ use std::io::IoResult; use std::io::net::ip::SocketAddr; -use {HttpResult}; -use version::{HttpVersion}; -use method::Method::{mod, Get, Head}; +use hc::{HttpResult}; +use hc::version::{HttpVersion}; +use hc::method::Method::{mod, Get, Head}; use header::Headers; use header::common::{ContentLength, TransferEncoding}; -use http::{read_request_line}; -use http::HttpReader; -use http::HttpReader::{SizedReader, ChunkedReader, EmptyReader}; -use uri::RequestUri; +use hc::http::{read_request_line}; +use hc::http::HttpReader; +use hc::http::HttpReader::{SizedReader, ChunkedReader, EmptyReader}; +use hc::uri::RequestUri; /// A request bundles several parts of an incoming `NetworkStream`, given to a `Handler`. pub struct Request<'a> { diff --git a/src/server/response.rs b/src/server/src/response.rs similarity index 96% rename from src/server/response.rs rename to src/server/src/response.rs index 7934dc23e7..6b5253a1b6 100644 --- a/src/server/response.rs +++ b/src/server/src/response.rs @@ -8,11 +8,11 @@ use time::now_utc; use header; use header::common; -use http::{CR, LF, LINE_ENDING, HttpWriter}; -use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter}; -use status; +use hc::http::{CR, LF, LINE_ENDING, HttpWriter}; +use hc::http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter}; +use hc::status; use net::{Fresh, Streaming}; -use version; +use hc::version; /// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`. pub struct Response<'a, W = Fresh> {