Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #33 from danlrobertson/impl_serialize_for_cookie
Browse files Browse the repository at this point in the history
Implement Into<cookie::Cookie> for Cookie
  • Loading branch information
jgraham committed Jun 1, 2016
2 parents f3b08dc + dab3f1f commit 2ee8645
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -12,3 +12,5 @@ log = "0.3.5"
regex = "0.1.47"
rustc-serialize = "0.3.16"
hyper = {version = "0.9", default-features = false}
cookie = {version = "0.2.4"}
time = "0.1"
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -5,6 +5,8 @@ extern crate log;
extern crate rustc_serialize;
extern crate hyper;
extern crate regex;
extern crate cookie;
extern crate time;

#[macro_use] pub mod macros;
pub mod httpapi;
Expand Down
24 changes: 24 additions & 0 deletions src/response.rs
@@ -1,6 +1,9 @@
use rustc_serialize::json;

use common::{Nullable, Date};
use cookie;
use time;
use std::collections::BTreeMap;

#[derive(Debug)]
pub enum WebDriverResponse {
Expand Down Expand Up @@ -116,6 +119,27 @@ impl Cookie {
}
}

impl Into<cookie::Cookie> for Cookie {
fn into(self) -> cookie::Cookie {
cookie::Cookie {
name: self.name,
value: self.value,
expires: match self.expiry {
Nullable::Value(Date(expiry)) => {
Some(time::at(time::Timespec::new(expiry as i64, 0)))
},
Nullable::Null => None
},
max_age: None,
domain: self.domain.into(),
path: self.path.into(),
secure: self.secure,
httponly: self.httpOnly,
custom: BTreeMap::new()
}
}
}

#[derive(RustcEncodable, Debug)]
pub struct CookieResponse {
pub value: Vec<Cookie>
Expand Down

0 comments on commit 2ee8645

Please sign in to comment.