mirror of https://github.com/rwf2/Rocket.git
Remove Rocket::from_hyp in favor of Rocket::new.
This commit is contained in:
parent
216b30cb78
commit
07204a25dd
|
@ -1,8 +1,8 @@
|
||||||
use std::io::{BufRead, Read, Cursor, BufReader};
|
use std::io::{BufRead, Read, Cursor, BufReader};
|
||||||
|
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
|
buffer: Vec<u8>,
|
||||||
stream: Cursor<Vec<u8>>,
|
stream: Cursor<Vec<u8>>,
|
||||||
buffer: Vec<u8>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::io::Read;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ use super::{FromParam, FromSegments};
|
||||||
|
|
||||||
use router::Route;
|
use router::Route;
|
||||||
use http::uri::{URI, URIBuf};
|
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};
|
use http::{Method, ContentType, Cookies};
|
||||||
|
|
||||||
/// The type for all incoming web requests.
|
/// The type for all incoming web requests.
|
||||||
|
@ -186,38 +185,33 @@ impl Request {
|
||||||
self.headers.set::<header::ContentType>(hyper_ct)
|
self.headers.set::<header::ContentType>(hyper_ct)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Rocket Request from a Hyper Request.
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn from_hyp<'h, 'k>(hyper_req: HyperRequest<'h, 'k>)
|
pub fn new(h_method: HyperMethod,
|
||||||
-> Result<Request, String> {
|
h_headers: HyperHeaders,
|
||||||
let (_, h_method, h_headers, h_uri, _, mut h_body) = hyper_req.deconstruct();
|
h_uri: HyperRequestUri)
|
||||||
|
-> Result<Request, String> {
|
||||||
let uri = match h_uri {
|
let uri = match h_uri {
|
||||||
HyperRequestUri::AbsolutePath(s) => URIBuf::from(s),
|
HyperRequestUri::AbsolutePath(s) => URIBuf::from(s),
|
||||||
_ => return Err(format!("Bad URI: {}", h_uri)),
|
_ => return Err(format!("Bad URI: {}", h_uri)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let method = match Method::from_hyp(&h_method) {
|
let method = match Method::from_hyp(&h_method) {
|
||||||
Some(m) => m,
|
Some(method) => method,
|
||||||
_ => return Err(format!("Bad method: {}", h_method)),
|
_ => return Err(format!("Bad method: {}", h_method)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let cookies = match h_headers.get::<HyperCookie>() {
|
let cookies = match h_headers.get::<HyperCookie>() {
|
||||||
// TODO: What to do about key?
|
// TODO: Retrieve key from config.
|
||||||
Some(cookie) => cookie.to_cookie_jar(&[]),
|
Some(cookie) => cookie.to_cookie_jar(&[]),
|
||||||
None => Cookies::new(&[]),
|
None => Cookies::new(&[]),
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: GRRR.
|
|
||||||
let mut data = vec![];
|
|
||||||
h_body.read_to_end(&mut data).unwrap();
|
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
params: RefCell::new(vec![]),
|
params: RefCell::new(vec![]),
|
||||||
method: method,
|
method: method,
|
||||||
cookies: cookies,
|
cookies: cookies,
|
||||||
uri: uri,
|
uri: uri,
|
||||||
data: data,
|
data: vec![], // TODO: Remove me.
|
||||||
headers: h_headers,
|
headers: h_headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,11 @@ impl Rocket {
|
||||||
// Get a copy of the URI for later use.
|
// Get a copy of the URI for later use.
|
||||||
let uri = hyp_req.uri.to_string();
|
let uri = hyp_req.uri.to_string();
|
||||||
|
|
||||||
// Try to create a Rocket request from the hyper request.
|
// Get all of the information from Hyper.
|
||||||
let request = match Request::from_hyp(hyp_req) {
|
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) => {
|
Ok(mut req) => {
|
||||||
self.preprocess_request(&mut req);
|
self.preprocess_request(&mut req);
|
||||||
req
|
req
|
||||||
|
|
Loading…
Reference in New Issue