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

use String instead of RequestUri for HTTP path #10

Closed
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
readme = "README.rst"
keywords = ["mio", "http", "websocket", "rotor"]
homepage = "http://github.com/tailhook/rotor-http"
version = "0.4.0"
version = "0.5.0"
authors = ["paul@colomiets.name"]

[dependencies]
Expand Down
20 changes: 5 additions & 15 deletions examples/hello_world_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate time;
use rotor::Scope;
use rotor_http::status::StatusCode::{self, NotFound};
use rotor_http::header::ContentLength;
use rotor_http::uri::RequestUri;
use rotor_stream::{Deadline, Accept, Stream};
use rotor_http::server::{RecvMode, Server, Head, Response, Parser};
use rotor_http::server::{Context as HttpContext};
Expand Down Expand Up @@ -68,20 +67,11 @@ impl Server for HelloWorld {
{
use self::HelloWorld::*;
scope.increment();
match head.uri {
RequestUri::AbsolutePath(ref p) if &p[..] == "/" => {
Some(Hello)
}
RequestUri::AbsolutePath(ref p) if &p[..] == "/num"
=> {
Some(GetNum)
}
RequestUri::AbsolutePath(p) => {
Some(HelloName(p[1..].to_string()))
}
_ => {
Some(PageNotFound)
}
match &head.path[..] {
"/" => Some(Hello),
"/num" => Some(GetNum),
p if p.starts_with("/") => Some(HelloName(p[1..].to_string())),
_ => Some(PageNotFound),
}
}
fn request_received(self, _data: &[u8], res: &mut Response,
Expand Down
20 changes: 5 additions & 15 deletions examples/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::thread;
use rotor::Scope;
use rotor_http::status::StatusCode::{self, NotFound};
use rotor_http::header::ContentLength;
use rotor_http::uri::RequestUri;
use rotor_stream::{Deadline, Accept, Stream};
use rotor_http::server::{RecvMode, Server, Head, Response, Parser};
use rotor_http::server::{Context as HttpContext};
Expand Down Expand Up @@ -70,20 +69,11 @@ impl Server for HelloWorld {
{
use self::HelloWorld::*;
scope.increment();
match head.uri {
RequestUri::AbsolutePath(ref p) if &p[..] == "/" => {
Some(Hello)
}
RequestUri::AbsolutePath(ref p) if &p[..] == "/num"
=> {
Some(GetNum)
}
RequestUri::AbsolutePath(p) => {
Some(HelloName(p[1..].to_string()))
}
_ => {
Some(PageNotFound)
}
match &head.path[..] {
"/" => Some(Hello),
"/num" => Some(GetNum),
p if p.starts_with("/") => Some(HelloName(p[1..].to_string())),
_ => Some(PageNotFound),
}
}
fn request_received(self, _data: &[u8], res: &mut Response,
Expand Down
20 changes: 5 additions & 15 deletions examples/threaded_reuse_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::os::unix::io::AsRawFd;
use rotor::Scope;
use rotor_http::status::StatusCode::{self, NotFound};
use rotor_http::header::ContentLength;
use rotor_http::uri::RequestUri;
use rotor_stream::{Deadline, Accept, Stream};
use rotor_http::server::{RecvMode, Server, Head, Response, Parser};
use rotor_http::server::{Context as HttpContext};
Expand Down Expand Up @@ -73,20 +72,11 @@ impl Server for HelloWorld {
{
use self::HelloWorld::*;
scope.increment();
match head.uri {
RequestUri::AbsolutePath(ref p) if &p[..] == "/" => {
Some(Hello)
}
RequestUri::AbsolutePath(ref p) if &p[..] == "/num"
=> {
Some(GetNum)
}
RequestUri::AbsolutePath(p) => {
Some(HelloName(p[1..].to_string()))
}
_ => {
Some(PageNotFound)
}
match &head.path[..] {
"/" => Some(Hello),
"/num" => Some(GetNum),
p if p.starts_with("/") => Some(HelloName(p[1..].to_string())),
_ => Some(PageNotFound),
}
}
fn request_received(self, _data: &[u8], res: &mut Response,
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ pub use hyper::status as status;
pub use hyper::header as header;
pub use hyper::version as version;
pub use hyper::method as method;
pub use hyper::uri as uri;
8 changes: 3 additions & 5 deletions src/server/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use hyper::version::HttpVersion as Version;
use hyper::status::StatusCode::{self, BadRequest};
use hyper::method::Method;
use hyper::uri::RequestUri;
use hyper::header::Headers;
use httparse;

Expand All @@ -14,13 +13,13 @@ use super::MAX_HEADERS_NUM;
/// We don't have a request object because it is structured differently
/// based on whether it is buffered or streaming, chunked or http2, etc.
///
/// Note: we do our base to keep Head object same for HTTP 1-2 and HTTPS
/// Note: we intend to keep the Head object the same for HTTP 1-2 and HTTPS
pub struct Head {
// TODO(tailhook) add source IP address
pub version: Version,
pub https: bool,
pub method: Method,
pub uri: RequestUri,
pub path: String,
pub headers: Headers,
}

Expand All @@ -37,8 +36,7 @@ impl Head {
else { Version::Http10 },
method: try!(raw.method.unwrap().parse()
.map_err(|_| BadRequest)),
uri: try!(raw.path.unwrap().parse()
.map_err(|_| BadRequest)),
path: raw.path.unwrap().to_owned(),
headers: try!(Headers::from_raw(raw.headers)
.map_err(|_| BadRequest)),
})
Expand Down