Remove Rocket::from_hyp in favor of Rocket::new.

This commit is contained in:
Sergio Benitez 2016-10-08 21:37:28 -07:00
parent 216b30cb78
commit 07204a25dd
3 changed files with 14 additions and 17 deletions

View File

@ -1,8 +1,8 @@
use std::io::{BufRead, Read, Cursor, BufReader};
pub struct Data {
buffer: Vec<u8>,
stream: Cursor<Vec<u8>>,
buffer: Vec<u8>
}
impl Data {

View File

@ -1,4 +1,3 @@
use std::io::Read;
use std::cell::RefCell;
use std::fmt;
@ -10,7 +9,7 @@ use super::{FromParam, FromSegments};
use router::Route;
use http::uri::{URI, URIBuf};
use http::hyper::{header, HyperCookie, HyperHeaders, HyperRequest, HyperRequestUri};
use http::hyper::{header, HyperCookie, HyperHeaders, HyperMethod, HyperRequestUri};
use http::{Method, ContentType, Cookies};
/// The type for all incoming web requests.
@ -186,38 +185,33 @@ impl Request {
self.headers.set::<header::ContentType>(hyper_ct)
}
/// Create a Rocket Request from a Hyper Request.
#[doc(hidden)]
pub fn from_hyp<'h, 'k>(hyper_req: HyperRequest<'h, 'k>)
pub fn new(h_method: HyperMethod,
h_headers: HyperHeaders,
h_uri: HyperRequestUri)
-> Result<Request, String> {
let (_, h_method, h_headers, h_uri, _, mut h_body) = hyper_req.deconstruct();
let uri = match h_uri {
HyperRequestUri::AbsolutePath(s) => URIBuf::from(s),
_ => return Err(format!("Bad URI: {}", h_uri)),
};
let method = match Method::from_hyp(&h_method) {
Some(m) => m,
Some(method) => method,
_ => return Err(format!("Bad method: {}", h_method)),
};
let cookies = match h_headers.get::<HyperCookie>() {
// TODO: What to do about key?
// TODO: Retrieve key from config.
Some(cookie) => cookie.to_cookie_jar(&[]),
None => Cookies::new(&[]),
};
// FIXME: GRRR.
let mut data = vec![];
h_body.read_to_end(&mut data).unwrap();
let request = Request {
params: RefCell::new(vec![]),
method: method,
cookies: cookies,
uri: uri,
data: data,
data: vec![], // TODO: Remove me.
headers: h_headers,
};

View File

@ -44,8 +44,11 @@ impl Rocket {
// Get a copy of the URI for later use.
let uri = hyp_req.uri.to_string();
// Try to create a Rocket request from the hyper request.
let request = match Request::from_hyp(hyp_req) {
// Get all of the information from Hyper.
let (_, h_method, h_headers, h_uri, _, mut _body) = hyp_req.deconstruct();
// Try to create a Rocket request from the hyper request info.
let request = match Request::new(h_method, h_headers, h_uri) {
Ok(mut req) => {
self.preprocess_request(&mut req);
req