Skip to content

Commit

Permalink
Keep an op-log for sync 'CookieJar'.
Browse files Browse the repository at this point in the history
In brief, this commit:

  * Updates to the latest upstream 'cookie', fixing a memory leak.
  * Make changes to 'CookieJar' observable only through 'pending()'.
  * Deprecates 'Client::new()' in favor of 'Client::tracked()'.
  * Makes 'dispatch()' on tracked 'Client's synchronize on cookies.
  * Makes 'Client::untracked()' actually untracked.

This commit updates to the latest 'cookie' which removes support for
'Sync' cookie jars. Instead of relying on 'cookie', this commit
implements an op-log based 'CookieJar' which internally keeps track of
changes. The API is such that changes are only observable through
specialized '_pending()' methods.
  • Loading branch information
SergioBenitez committed Oct 15, 2020
1 parent 2f330d2 commit 5d9035d
Show file tree
Hide file tree
Showing 93 changed files with 465 additions and 295 deletions.
2 changes: 0 additions & 2 deletions contrib/lib/src/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,5 @@ mod tests {
assert_eq!(pool_size, database_config.pool_size);
assert_eq!(true, database_config.extras.contains_key("certs"));
assert_eq!(true, database_config.extras.contains_key("key"));

println!("{:#?}", database_config);
}
}
2 changes: 1 addition & 1 deletion contrib/lib/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl Template {
///
/// fn main() {
/// let rocket = rocket::ignite().attach(Template::fairing());
/// let client = Client::new(rocket).expect("valid rocket");
/// let client = Client::untracked(rocket).expect("valid rocket");
///
/// // Create a `context`. Here, just an empty `HashMap`.
/// let mut context = HashMap::new();
Expand Down
16 changes: 8 additions & 8 deletions contrib/lib/tests/compress_responder.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod compress_responder_tests {

#[test]
fn test_prioritizes_brotli() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -90,7 +90,7 @@ mod compress_responder_tests {

#[test]
fn test_br_font() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/font")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -114,7 +114,7 @@ mod compress_responder_tests {

#[test]
fn test_fallback_gzip() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate, gzip"))
Expand All @@ -137,7 +137,7 @@ mod compress_responder_tests {

#[test]
fn test_does_not_recompress() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/already_encoded")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -160,7 +160,7 @@ mod compress_responder_tests {

#[test]
fn test_does_not_compress_explicit_identity() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/identity")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -178,7 +178,7 @@ mod compress_responder_tests {

#[test]
fn test_ignore_exceptions() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/image")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -202,7 +202,7 @@ mod compress_responder_tests {

#[test]
fn test_ignores_unimplemented_encodings() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate"))
Expand All @@ -220,7 +220,7 @@ mod compress_responder_tests {

#[test]
fn test_respects_identity_only() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "identity"))
Expand Down
20 changes: 10 additions & 10 deletions contrib/lib/tests/compression_fairing.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod compression_fairing_tests {

#[test]
fn test_prioritizes_brotli() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -109,7 +109,7 @@ mod compression_fairing_tests {

#[test]
fn test_br_font() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/font")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -133,7 +133,7 @@ mod compression_fairing_tests {

#[test]
fn test_fallback_gzip() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate, gzip"))
Expand All @@ -156,7 +156,7 @@ mod compression_fairing_tests {

#[test]
fn test_does_not_recompress() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/already_encoded")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -179,7 +179,7 @@ mod compression_fairing_tests {

#[test]
fn test_does_not_compress_explicit_identity() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/identity")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -197,7 +197,7 @@ mod compression_fairing_tests {

#[test]
fn test_does_not_compress_image() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/image")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -215,7 +215,7 @@ mod compression_fairing_tests {

#[test]
fn test_ignores_unimplemented_encodings() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "deflate"))
Expand All @@ -233,7 +233,7 @@ mod compression_fairing_tests {

#[test]
fn test_respects_identity_only() {
let client = Client::new(rocket()).expect("valid rocket instance");
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client
.get("/")
.header(Header::new("Accept-Encoding", "identity"))
Expand All @@ -251,7 +251,7 @@ mod compression_fairing_tests {

#[test]
fn test_does_not_compress_custom_exception() {
let client = Client::new(rocket_tar_exception()).expect("valid rocket instance");
let client = Client::tracked(rocket_tar_exception()).expect("valid rocket instance");
let mut response = client
.get("/tar")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand All @@ -269,7 +269,7 @@ mod compression_fairing_tests {

#[test]
fn test_compress_custom_removed_exception() {
let client = Client::new(rocket_tar_exception()).expect("valid rocket instance");
let client = Client::tracked(rocket_tar_exception()).expect("valid rocket instance");
let mut response = client
.get("/image")
.header(Header::new("Accept-Encoding", "deflate, gzip, br"))
Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/tests/helmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod helmet_tests {
macro_rules! dispatch {
($helmet:expr, $closure:expr) => {{
let rocket = rocket::ignite().mount("/", routes![hello]).attach($helmet);
let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();
let response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
$closure(response)
Expand Down
12 changes: 6 additions & 6 deletions contrib/lib/tests/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ mod static_tests {

#[test]
fn test_static_no_index() {
let client = Client::new(rocket()).expect("valid rocket");
let client = Client::tracked(rocket()).expect("valid rocket");
assert_all(&client, "no_index", REGULAR_FILES, true);
assert_all(&client, "no_index", HIDDEN_FILES, false);
assert_all(&client, "no_index", INDEXED_DIRECTORIES, false);
}

#[test]
fn test_static_hidden() {
let client = Client::new(rocket()).expect("valid rocket");
let client = Client::tracked(rocket()).expect("valid rocket");
assert_all(&client, "dots", REGULAR_FILES, true);
assert_all(&client, "dots", HIDDEN_FILES, true);
assert_all(&client, "dots", INDEXED_DIRECTORIES, false);
}

#[test]
fn test_static_index() {
let client = Client::new(rocket()).expect("valid rocket");
let client = Client::tracked(rocket()).expect("valid rocket");
assert_all(&client, "index", REGULAR_FILES, true);
assert_all(&client, "index", HIDDEN_FILES, false);
assert_all(&client, "index", INDEXED_DIRECTORIES, true);
Expand All @@ -97,7 +97,7 @@ mod static_tests {

#[test]
fn test_static_all() {
let client = Client::new(rocket()).expect("valid rocket");
let client = Client::tracked(rocket()).expect("valid rocket");
assert_all(&client, "both", REGULAR_FILES, true);
assert_all(&client, "both", HIDDEN_FILES, true);
assert_all(&client, "both", INDEXED_DIRECTORIES, true);
Expand Down Expand Up @@ -129,7 +129,7 @@ mod static_tests {
fn catch_two(a: &RawStr, b: &RawStr) -> String { format!("{}/{}", a, b) }

let rocket = rocket().mount("/default", routes![catch_one, catch_two]);
let client = Client::new(rocket).expect("valid rocket");
let client = Client::tracked(rocket).expect("valid rocket");

let response = client.get("/default/ireallydontexist").dispatch();
assert_eq!(response.status(), Status::Ok);
Expand All @@ -146,7 +146,7 @@ mod static_tests {

#[test]
fn test_redirection() {
let client = Client::new(rocket()).expect("valid rocket");
let client = Client::tracked(rocket()).expect("valid rocket");

// Redirection only happens if enabled, and doesn't affect index behaviour.
let response = client.get("/no_index/inner").dispatch();
Expand Down
6 changes: 3 additions & 3 deletions contrib/lib/tests/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod templates_tests {

#[test]
fn test_template_metadata_with_tera() {
let client = Client::new(rocket()).unwrap();
let client = Client::tracked(rocket()).unwrap();

let response = client.get("/tera/txt_test").dispatch();
assert_eq!(response.status(), Status::Ok);
Expand Down Expand Up @@ -107,7 +107,7 @@ mod templates_tests {

#[test]
fn test_template_metadata_with_handlebars() {
let client = Client::new(rocket()).unwrap();
let client = Client::tracked(rocket()).unwrap();

let response = client.get("/hbs/test").dispatch();
assert_eq!(response.status(), Status::Ok);
Expand Down Expand Up @@ -144,7 +144,7 @@ mod templates_tests {
write_file(&reload_path, INITIAL_TEXT);

// set up the client. if we can't reload templates, then just quit
let client = Client::new(rocket()).unwrap();
let client = Client::tracked(rocket()).unwrap();
let res = client.get("/is_reloading").dispatch();
if res.status() != Status::Ok {
return;
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/tests/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ foo!("/hello/<name>", name);
#[test]
fn test_reexpansion() {
let rocket = rocket::ignite().mount("/", routes![easy, hard, hi]);
let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let response = client.get("/easy/327").dispatch();
assert_eq!(response.into_string().unwrap(), "easy id: 327");
Expand All @@ -60,7 +60,7 @@ index!(i32);
#[test]
fn test_index() {
let rocket = rocket::ignite().mount("/", routes![index]).manage(100i32);
let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let response = client.get("/").dispatch();
assert_eq!(response.into_string().unwrap(), "Thing: 100");
Expand Down
6 changes: 3 additions & 3 deletions core/codegen/tests/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum Foo<'r> {

#[rocket::async_test]
async fn responder_foo() {
let client = Client::new(rocket::ignite()).await.expect("valid rocket");
let client = Client::tracked(rocket::ignite()).await.expect("valid rocket");
let local_req = client.get("/");
let req = local_req.inner();

Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct Bar<'r> {

#[rocket::async_test]
async fn responder_bar() {
let client = Client::new(rocket::ignite()).await.expect("valid rocket");
let client = Client::tracked(rocket::ignite()).await.expect("valid rocket");
let local_req = client.get("/");
let req = local_req.inner();

Expand All @@ -95,7 +95,7 @@ pub struct Baz {

#[rocket::async_test]
async fn responder_baz() {
let client = Client::new(rocket::ignite()).await.expect("valid rocket");
let client = Client::tracked(rocket::ignite()).await.expect("valid rocket");
let local_req = client.get("/");
let req = local_req.inner();

Expand Down
2 changes: 1 addition & 1 deletion core/codegen/tests/route-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn simple(simple: Simple) -> String { simple.0 }
#[test]
fn test_data() {
let rocket = rocket::ignite().mount("/", routes![form, simple]);
let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let response = client.post("/f")
.header(ContentType::Form)
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/tests/route-format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_formats() {
.mount("/", routes![json, xml, json_long, msgpack_long, msgpack,
plain, binary, other]);

let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let response = client.post("/").header(ContentType::JSON).dispatch();
assert_eq!(response.into_string().unwrap(), "json");
Expand Down Expand Up @@ -83,7 +83,7 @@ fn test_custom_formats() {
let rocket = rocket::ignite()
.mount("/", routes![get_foo, post_foo, get_bar_baz, put_bar_baz]);

let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let foo_a = Accept::new(&[MediaType::new("application", "foo").into()]);
let foo_ct = ContentType::new("application", "foo");
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/tests/route-ranking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn get3(_number: u64) -> &'static str { "3" }
#[test]
fn test_ranking() {
let rocket = rocket::ignite().mount("/", routes![get0, get1, get2, get3]);
let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let response = client.get("/0").dispatch();
assert_eq!(response.into_string().unwrap(), "0");
Expand All @@ -44,7 +44,7 @@ fn test_rank_collision() {
use rocket::error::LaunchErrorKind;

let rocket = rocket::ignite().mount("/", routes![get0, get0b]);
let client_result = Client::new(rocket);
let client_result = Client::tracked(rocket);
match client_result.as_ref().map_err(|e| e.kind()) {
Err(LaunchErrorKind::Collision(..)) => { /* o.k. */ },
Ok(_) => panic!("client succeeded unexpectedly"),
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/tests/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn test_full_route() {
.mount("/1", routes![post1])
.mount("/2", routes![post2]);

let client = Client::new(rocket).unwrap();
let client = Client::tracked(rocket).unwrap();

let a = "A%20A";
let name = "Bob%20McDonald";
Expand Down
6 changes: 0 additions & 6 deletions core/codegen/tests/ui-fail-nightly/responder-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ error[E0277]: the trait bound `Header<'_>: From<u8>` is not satisfied
|
= help: the following implementations were found:
<Header<'static> as From<&Cookie<'_>>>
<Header<'static> as From<&CookieCrumb>>
<Header<'static> as From<Cookie<'_>>>
<Header<'static> as From<CookieCrumb>>
= note: required because of the requirements on the impl of `Into<Header<'_>>` for `u8`

error[E0277]: the trait bound `u8: Responder<'_, '_>` is not satisfied
Expand All @@ -35,9 +33,7 @@ error[E0277]: the trait bound `Header<'_>: From<u8>` is not satisfied
|
= help: the following implementations were found:
<Header<'static> as From<&Cookie<'_>>>
<Header<'static> as From<&CookieCrumb>>
<Header<'static> as From<Cookie<'_>>>
<Header<'static> as From<CookieCrumb>>
= note: required because of the requirements on the impl of `Into<Header<'_>>` for `u8`

error[E0277]: the trait bound `Header<'_>: From<std::string::String>` is not satisfied
Expand All @@ -48,9 +44,7 @@ error[E0277]: the trait bound `Header<'_>: From<std::string::String>` is not sat
|
= help: the following implementations were found:
<Header<'static> as From<&Cookie<'_>>>
<Header<'static> as From<&CookieCrumb>>
<Header<'static> as From<Cookie<'_>>>
<Header<'static> as From<CookieCrumb>>
= note: required because of the requirements on the impl of `Into<Header<'_>>` for `std::string::String`

error[E0277]: the trait bound `usize: Responder<'_, '_>` is not satisfied
Expand Down
Loading

0 comments on commit 5d9035d

Please sign in to comment.