From 7132c3c7117442699fa1c2c683641995dc0bd3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sat, 20 Sep 2014 22:37:05 +0200 Subject: [PATCH] Fix build --- Cargo.toml | 2 +- src/lib.rs | 4 ++-- src/parser.rs | 20 +++++++++++--------- src/response.rs | 6 ++++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 468495f..5014999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ name = "cookie" version = "0.1.0" authors = ["Zach Pomerantz "] -[[lib]] +[lib] name = "cookie" path = "src/lib.rs" diff --git a/src/lib.rs b/src/lib.rs index 82aafee..e217bbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,9 +15,9 @@ extern crate url; extern crate serialize; extern crate iron; extern crate http; -extern crate crypto = "rust-crypto"; +extern crate "rust-crypto" as crypto; #[cfg(test)] -extern crate test = "iron-test"; +extern crate "iron-test" as test; pub use cookie::Cookie; pub use parser::CookieParser; diff --git a/src/parser.rs b/src/parser.rs index b6165db..9e45491 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2,11 +2,11 @@ use std::collections::treemap::TreeMap; use url::lossy_utf8_percent_decode; -use serialize::json; -use serialize::json::{Json, Null}; -use iron::{Request, Response, Middleware, Status, Continue}; +use serialize::json::{mod, Json, Null}; +use iron::{Request, Response, BeforeMiddleware, IronResult}; use super::Cookie; use crypto::util::fixed_time_eq; +use iron::typemap::Assoc; /// The cookie parsing `Middleware`. /// @@ -20,6 +20,8 @@ pub struct CookieParser { secret: Option } +impl Assoc for Cookie {} + impl CookieParser { /// Create a new instance of the cookie parsing `Middleware`. /// @@ -37,11 +39,11 @@ impl CookieParser { pub fn signed(secret: String) -> CookieParser { CookieParser{ secret: Some(secret) } } } -impl Middleware for CookieParser { +impl BeforeMiddleware for CookieParser { /// Parse the cookie received in the HTTP header. /// /// This will parse the body of a cookie into the alloy, under type `Cookie`. - fn enter(&mut self, req: &mut Request, _res: &mut Response) -> Status { + fn before(&self, req: &mut Request) -> IronResult<()> { // Initialize a cookie. This will store parsed cookies and generate signatures. let mut new_cookie = Cookie::new(self.secret.clone()); @@ -55,7 +57,7 @@ impl Middleware for CookieParser { .split(';') // Decode from uri component encoding .map(|substr| { - let vec: Vec<&str> = substr.splitn('=', 1).collect(); + let vec: Vec<&str> = substr.splitn(1, '=').collect(); let key = from_rfc_compliant(vec[0]); let val = from_rfc_compliant(vec[1]); (key, val) }) @@ -71,8 +73,8 @@ impl Middleware for CookieParser { }, None => () } - req.alloy.insert(new_cookie); - Continue + req.extensions.insert::(new_cookie); + Ok(()) } } @@ -140,7 +142,7 @@ fn parse_json(&(ref key, ref val): &(String, String), json: &mut Json) -> bool { #[cfg(test)] mod test { use std::collections::{HashMap, TreeMap}; - use iron::{Request, Middleware}; + use iron::Request; use test::mock::{request, response}; use super::*; use super::super::cookie::*; diff --git a/src/response.rs b/src/response.rs index b913f7f..56fa8d1 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,7 +1,7 @@ //! Setting functionality - set cookie data use url::{utf8_percent_encode, FORM_URLENCODED_ENCODE_SET}; -use serialize::json::{Json, Number, String, Boolean, List, Object, Null}; +use serialize::json::{mod, Json, String, Boolean, List, Object, Null}; use iron::Response; use super::Cookie; use time::Tm; @@ -81,7 +81,9 @@ fn stringify_json(json: &Json) -> String { let ary: Vec = list.iter().map(stringify_json).collect(); "[".to_string().append(ary.connect(",").as_slice()).append("]") }, - Number(number) => number.to_string(), + json::I64(number) => number.to_string(), + json::U64(number) => number.to_string(), + json::F64(number) => number.to_string(), String(ref string) => "\"".to_string().append(string.as_slice()).append("\""), Boolean(true) => "true".to_string(), Boolean(false) => "false".to_string(),