Skip to content

Commit

Permalink
Split the 'http' module into its own 'rocket_http' crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Jun 7, 2018
1 parent 900e716 commit df71111
Show file tree
Hide file tree
Showing 44 changed files with 432 additions and 203 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"core/lib/",
"core/codegen/",
"core/codegen_next/",
"core/http/",
"contrib/lib",
"examples/cookies",
"examples/errors",
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ build = "build.rs"
plugin = true

[dependencies]
rocket = { version = "0.4.0-dev", path = "../lib/" }
rocket_http = { version = "0.4.0-dev", path = "../http" }
indexmap = "1.0"
log = "0.4"

[dev-dependencies]
compiletest_rs = "0.3.5"
rocket = { version = "0.4.0-dev", path = "../lib" }

[build-dependencies]
yansi = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/src/decorators/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use syntax::parse::token;
use syntax::symbol::LocalInternedString;
use syntax::ptr::P;

use rocket::http::{Method, MediaType};
use rocket_http::{Method, MediaType};

fn method_to_path(ecx: &ExtCtxt, method: Method) -> Path {
quote_enum!(ecx, method => ::rocket::http::Method {
quote_enum!(ecx, method => ::rocket_http::Method -> ::rocket::http::Method {
Options, Get, Post, Put, Delete, Head, Trace, Connect, Patch;
})
}
Expand Down
9 changes: 1 addition & 8 deletions core/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,18 @@
//! ```

#[macro_use] extern crate log;
extern crate syntax;
extern crate syntax_ext;
extern crate syntax_pos;
extern crate rustc_plugin;
extern crate rocket;
extern crate rocket_http;
extern crate indexmap;

#[macro_use] mod utils;
mod parser;
mod macros;
mod decorators;

use std::env;
use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
Expand Down Expand Up @@ -279,11 +277,6 @@ macro_rules! register_macros {
/// Compiler hook for Rust to register plugins.
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
// Enable logging early if the DEBUG_ENV_VAR is set.
if env::var(DEBUG_ENV_VAR).is_ok() {
::rocket::logger::init(::rocket::config::LoggingLevel::Debug);
}

register_macros!(reg,
"routes" => routes,
"catchers" => catchers,
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/parser/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use syntax::ast::*;
use syntax::ext::base::{ExtCtxt, Annotatable};
use syntax::codemap::{Span, Spanned, dummy_spanned};

use rocket::http::Status;
use rocket_http::Status;

use utils::{span, MetaItemExt};
use super::Function;
Expand Down
6 changes: 3 additions & 3 deletions core/codegen/src/parser/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use utils::{MetaItemExt, SpanExt, span, is_valid_ident};
use super::Function;
use super::keyvalue::KVSpanned;
use super::uri::validate_uri;
use rocket::http::{Method, MediaType};
use rocket::http::uri::Uri;
use rocket_http::{Method, MediaType};
use rocket_http::uri::Uri;

/// This structure represents the parsed `route` attribute.
///
Expand Down Expand Up @@ -131,7 +131,7 @@ impl RouteParams {
}

fn is_valid_method(method: Method) -> bool {
use rocket::http::Method::*;
use rocket_http::Method::*;
match method {
Get | Put | Post | Delete | Head | Patch | Options => true,
Trace | Connect => false
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/parser/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use syntax::ast::*;
use syntax::codemap::{Span, Spanned, dummy_spanned};
use syntax::ext::base::ExtCtxt;

use rocket::http::uri::Uri;
use rocket_http::uri::Uri;
use super::route::param_to_ident;
use utils::{span, SpanExt, is_valid_ident};

Expand Down
17 changes: 14 additions & 3 deletions core/codegen/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ use syntax::fold::Folder;
use syntax::attr::HasAttrs;
use syntax::ptr::P;

macro_rules! debug {
($($t:tt)*) => (
// Enable debug logs if the DEBUG_ENV_VAR is set.
if ::std::env::var(::DEBUG_ENV_VAR).is_ok() {
eprintln!("--> {}:{} ({})", file!(), line!(), module_path!());
eprintln!($($t)*);
eprintln!();
}
)
}

pub fn span<T>(t: T, span: Span) -> Spanned<T> {
Spanned { node: t, span: span }
}
Expand Down Expand Up @@ -133,12 +144,12 @@ pub fn split_idents(path: &str) -> Vec<Ident> {
}

macro_rules! quote_enum {
($ecx:expr, $var:expr => $(::$root:ident)+
($ecx:expr, $var:expr => $(::$from_root:ident)+ -> $(::$to_root:ident)+
{ $($variant:ident),+ ; $($extra:pat => $result:expr),* }) => ({
use syntax::codemap::DUMMY_SP;
use syntax::ast::Ident;
use $(::$root)+::*;
let root_idents = vec![$(Ident::from_str(stringify!($root))),+];
use $(::$from_root)+::*;
let root_idents = vec![$(Ident::from_str(stringify!($to_root))),+];
match $var {
$($variant => {
let variant = Ident::from_str(stringify!($variant));
Expand Down
40 changes: 40 additions & 0 deletions core/http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "rocket_http"
version = "0.4.0-dev"
authors = ["Sergio Benitez <[email protected]>"]
description = """
Types, traits, and parsers for HTTP requests, responses, and headers.
"""
documentation = "https://api.rocket.rs/rocket_http/"
homepage = "https://rocket.rs"
repository = "https://github.com/SergioBenitez/Rocket"
readme = "../../README.md"
keywords = ["rocket", "web", "framework", "http"]
license = "MIT/Apache-2.0"
categories = ["web-programming"]

[features]
tls = ["rustls", "hyper-sync-rustls"]

[dependencies]
pear = { git = "http://github.com/SergioBenitez/Pear", rev = "54667ae" }
smallvec = "0.6"
percent-encoding = "1"
hyper = { version = "0.10.13", default-features = false }
time = "0.1"
indexmap = "1.0"
rustls = { version = "0.12.0", optional = true }

[dependencies.cookie]
git = "https://github.com/alexcrichton/cookie-rs"
rev = "0365a18"
features = ["percent-encode", "secure"]

[dependencies.hyper-sync-rustls]
version = "=0.3.0-rc.2"
features = ["server"]
optional = true

[dev-dependencies]
rocket = { version = "0.4.0-dev", path = "../lib" }
rocket_codegen = { version = "0.4.0-dev", path = "../codegen" }
16 changes: 13 additions & 3 deletions core/lib/src/http/accept.rs → core/http/src/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::fmt;

use smallvec::SmallVec;

use {Header, MediaType};
use ext::IntoCollection;
use http::{Header, MediaType};
use http::parse::parse_accept;
use parse::parse_accept;

/// A `MediaType` with an associated quality value.
#[derive(Debug, Clone, PartialEq)]
Expand All @@ -18,6 +18,7 @@ impl QMediaType {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{MediaType, QMediaType};
///
/// let q_type = QMediaType(MediaType::HTML, Some(0.3));
Expand All @@ -33,6 +34,7 @@ impl QMediaType {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{MediaType, QMediaType};
///
/// let q_type = QMediaType(MediaType::HTML, Some(0.3));
Expand All @@ -51,6 +53,7 @@ impl QMediaType {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{MediaType, QMediaType};
///
/// let q_type = QMediaType(MediaType::HTML, Some(0.3));
Expand Down Expand Up @@ -139,6 +142,7 @@ impl PartialEq for AcceptParams {
/// Construct an `Accept` header with a single `application/json` media type:
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::Accept;
///
/// # #[allow(unused_variables)]
Expand All @@ -151,6 +155,7 @@ impl PartialEq for AcceptParams {
/// where an `Into<Header>` is expected:
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::Accept;
/// use rocket::response::Response;
///
Expand Down Expand Up @@ -193,6 +198,7 @@ impl Accept {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{QMediaType, MediaType, Accept};
///
/// // Construct an `Accept` via a `Vec<QMediaType>`.
Expand Down Expand Up @@ -228,6 +234,7 @@ impl Accept {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{QMediaType, MediaType, Accept};
///
/// let media_types = vec![
Expand Down Expand Up @@ -274,6 +281,7 @@ impl Accept {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{QMediaType, MediaType, Accept};
///
/// let accept = Accept::new(QMediaType(MediaType::XML, None));
Expand All @@ -291,6 +299,7 @@ impl Accept {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{QMediaType, MediaType, Accept};
///
/// let qmedia_types = vec![
Expand Down Expand Up @@ -321,6 +330,7 @@ impl Accept {
/// # Example
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::{QMediaType, MediaType, Accept};
///
/// let qmedia_types = vec![
Expand Down Expand Up @@ -378,7 +388,7 @@ impl Into<Header<'static>> for Accept {

#[cfg(test)]
mod test {
use http::{Accept, MediaType};
use {Accept, MediaType};

macro_rules! assert_preference {
($string:expr, $expect:expr) => (
Expand Down
Loading

0 comments on commit df71111

Please sign in to comment.