Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reading cookies/headers from context #252

Open
tronikelis opened this issue Jun 2, 2023 · 1 comment
Open

reading cookies/headers from context #252

tronikelis opened this issue Jun 2, 2023 · 1 comment

Comments

@tronikelis
Copy link

Hi, how do I read the headers and the cookies from the response?

I am testing a middleware that needs cookies like this:

let response = Testable::get(
    &app,
    "/",
    vec![("cookie".to_string(), cookie_header.clone())],
)
.await
.unwrap()
.expect_status(200, "OK");

And I am printing out everything like this:

println!("headers: {:#?}", context.headers);
println!("cookies: {:#?}", context.cookies);
println!("cookies__ {:#?}", context.get_cookies());

But every one of those 3 variables return empty:

running 3 tests
headers: {
    "server": "Thruster",
}
cookies: {}
headers: {
    "server": "Thruster",
}
cookies: {}
cookies__ []
headers: {
    "server": "Thruster",
}
cookies: {}
test hello_world ... cookies__ []
cookies__ []
ok
headers: {
    "server": "Thruster",
}
cookies: {}
cookies__ []
@tronikelis
Copy link
Author

@trezm and I am confused about the headers and cookies, I have some suggestions:

I think clear differentiation between request and response variables is needed

So something like this:

// from
context.set("foo", "bar");
// to
context.set_header("foo", "bar");

// from
context.cookie("foo", "bar", &CookieOptions::default());
// to
context.set_cookie("foo", "bar", &CookieOptions::default());

// from
context.headers;
// to
context.res_headers;

// I am confused about the methods below,
// the `context.cookie()` sets the header and thats it
// so these methods won't return anything?

// from
context.get_cookies();
// to
context.get_res_cookies();

// not sure what this does
context.set_cookies(cookies);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant