Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split hyper into smaller subpackages #200

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
/Cargo.lock
target/
Cargo.lock
44 changes: 32 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,16 +10,36 @@ license = "MIT"
authors = ["Sean McArthur <sean.monstar@gmail.com>",
"Jonathan Reem <jonathan.reem@gmail.com>"]

[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 = "*"
11 changes: 11 additions & 0 deletions publish-all.sh
Original file line number Diff line number Diff line change
@@ -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 .;
22 changes: 22 additions & 0 deletions src/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]

name = "hyper-client"
version = "0.1.0"
authors = ["Sean McArthur <sean.monstar@gmail.com>"]

[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 = "*"
29 changes: 24 additions & 5 deletions src/client/mod.rs → src/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T: Send>() {
_assert_send::<Request<net::Fresh>>();
_assert_send::<Response>();
}
14 changes: 7 additions & 7 deletions src/client/request.rs → src/client/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/client/response.rs → src/client/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S = HttpStream> {
Expand Down
7 changes: 7 additions & 0 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "hyper-core"
version = "0.1.0"
authors = [ "Sean McArthur <sean.mcarthur@gmail.com>" ]

[dependencies.url]
version = "*"
2 changes: 1 addition & 1 deletion src/http.rs → src/core/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
98 changes: 98 additions & 0 deletions src/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T> = Result<T, HttpError>;
/// 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<IoError> for HttpError {
fn from_error(err: IoError) -> HttpError {
HttpIoError(err)
}
}

impl FromError<url::ParseError> for HttpError {
fn from_error(err: url::ParseError) -> HttpError {
HttpUriError(err)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading