2016-03-15 03:43:52 +00:00
|
|
|
use error::Error;
|
2016-03-17 08:57:04 +00:00
|
|
|
use param::FromParam;
|
2016-07-16 04:09:08 +00:00
|
|
|
use method::Method;
|
2016-08-08 10:48:00 +00:00
|
|
|
use request::HyperHeaders;
|
2016-03-15 03:43:52 +00:00
|
|
|
|
2016-07-19 04:11:22 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2016-03-22 05:04:39 +00:00
|
|
|
pub struct Request<'a> {
|
2016-07-16 04:09:08 +00:00
|
|
|
params: Option<Vec<&'a str>>,
|
2016-08-08 10:48:00 +00:00
|
|
|
pub headers: &'a HyperHeaders, // TODO: Don't make pub?....
|
2016-07-16 04:09:08 +00:00
|
|
|
pub method: Method,
|
2016-04-04 04:53:25 +00:00
|
|
|
pub uri: &'a str,
|
|
|
|
pub data: &'a [u8]
|
2016-03-22 05:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Request<'a> {
|
2016-08-08 10:48:00 +00:00
|
|
|
pub fn new(headers: &'a HyperHeaders, method: Method, uri: &'a str,
|
|
|
|
params: Option<Vec<&'a str>>, data: &'a [u8]) -> Request<'a> {
|
2016-03-22 05:04:39 +00:00
|
|
|
Request {
|
2016-08-08 10:48:00 +00:00
|
|
|
headers: headers,
|
2016-07-16 04:09:08 +00:00
|
|
|
method: method,
|
2016-03-22 05:04:39 +00:00
|
|
|
params: params,
|
2016-04-04 04:53:25 +00:00
|
|
|
uri: uri,
|
|
|
|
data: data
|
2016-03-22 05:04:39 +00:00
|
|
|
}
|
Something works! A simple hacked-up handler, that is.
At the moment, I simply install the first route I see into the Rocket struct
directly. This is quite terrible. What's worse is that I assume that the Route's
path and handler are static! The handler, actually, does have to be static, but
its response may have whatever (valid) lifetime, though I'm not sure anything
but `static makes sense. I'll think about it.
In any case, the weird `static` restrictions need to be removed, and I need to
think about which lifetimes are safe here. IE: Must all routes be static? Can I
use a closure as a route? (that'd be neat). If so, how do we make that work?
In any case, it's nice to see SOMETHING work. Yay!
2016-03-15 07:41:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 05:04:39 +00:00
|
|
|
pub fn get_uri(&self) -> &'a str {
|
|
|
|
self.uri
|
2016-03-15 03:43:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 05:04:39 +00:00
|
|
|
pub fn get_param<T: FromParam<'a>>(&'a self, n: usize) -> Result<T, Error> {
|
2016-07-16 04:09:08 +00:00
|
|
|
if self.params.is_none() || n >= self.params.as_ref().unwrap().len() {
|
2016-03-22 05:04:39 +00:00
|
|
|
Err(Error::NoKey)
|
|
|
|
} else {
|
2016-07-16 04:09:08 +00:00
|
|
|
T::from_param(self.params.as_ref().unwrap()[n])
|
2016-03-22 05:04:39 +00:00
|
|
|
}
|
2016-03-15 03:43:52 +00:00
|
|
|
}
|
|
|
|
}
|