mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-31 23:02:37 +00:00
5d9035ddc1
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.
34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
use rocket::http::Header;
|
|
use rocket::local::blocking::Client;
|
|
|
|
#[test]
|
|
fn test_local_request_clone_soundness() {
|
|
let client = Client::tracked(rocket::ignite()).unwrap();
|
|
|
|
// creates two LocalRequest instances that shouldn't share the same req
|
|
let r1 = client.get("/").header(Header::new("key", "val1"));
|
|
let mut r2 = r1.clone();
|
|
|
|
// save the iterator, which internally holds a slice
|
|
let mut iter = r1.inner().headers().get("key");
|
|
|
|
// insert headers to force header map reallocation.
|
|
for i in 0..100 {
|
|
r2.add_header(Header::new(i.to_string(), i.to_string()));
|
|
}
|
|
|
|
// Replace the original key/val.
|
|
r2.add_header(Header::new("key", "val2"));
|
|
|
|
// Heap massage: so we've got crud to print.
|
|
let _: Vec<usize> = vec![0, 0xcafebabe, 31337, 0];
|
|
|
|
// Ensure we're good.
|
|
let s = iter.next().unwrap();
|
|
println!("{}", s);
|
|
|
|
// And that we've got the right data.
|
|
assert_eq!(r1.inner().headers().get("key").collect::<Vec<_>>(), vec!["val1"]);
|
|
assert_eq!(r2.inner().headers().get("key").collect::<Vec<_>>(), vec!["val1", "val2"]);
|
|
}
|