Can you provide rigth way to set Cookie in this example
wild-man opened this issue · comments
`
[macro_use] extern crate nickel;
extern crate nickel_postgres;
extern crate r2d2;
extern crate r2d2_postgres;
extern crate serde;
[macro_use] extern crate serde_json;
extern crate chrono;
[macro_use] extern crate postgres;
extern crate hyper;
//use std::env;
use r2d2::{Config, Pool};
use r2d2_postgres::{PostgresConnectionManager, SslMode};
use nickel_postgres::{PostgresMiddleware, PostgresRequestExtensions};
use nickel::{Nickel};
use std::io::Read;
use hyper::header::{Header, HeaderFormat, Headers, Cookie, CookiePair, SetCookie};
fn main() {
let mut server = Nickel::new();
let postgres_url = "postgresql://test@localhost";
let db_mgr = PostgresConnectionManager::new(postgres_url.as_ref(), SslMode::None).expect("Unable to connect to database");
let db_pool = Pool::new(Config::default(), db_mgr).expect("Unable to initialize connection pool");
server.utilize(PostgresMiddleware::with_pool(db_pool));
server.utilize(router! {
post "/test/" => |request, mut response| {
let mut c1 = CookiePair::new("test".to_owned(), "Done".to_owned());
c1.httponly = true;
let set_cookies = SetCookie(vec![c1]);
/*
let mut headers = Headers::new();
headers.set(Cookie(vec![c1]));
*/
response.set(set_cookies);
format!("Ok")
}
});
server.listen("127.0.0.1:6000");
}
`
I'm always the get error:
trait bound hyper::header::SetCookie: modifier::Modifier<nickel::Response<'_, _>>
is not satisfied
I try many ways to resolve this problem and fail with errors something like this:
the trait bound hyper::header::Cookie: hyper::header::Header
is not satisfied
error: the trait bound hyper::header::Cookie: hyper::header::HeaderFormat
is not satisfied
...
Thanks.