Crates.io | easycookie |
lib.rs | easycookie |
version | 1.0.3 |
source | src |
created_at | 2023-11-27 23:08:14.731021 |
updated_at | 2023-11-29 20:50:03.578896 |
description | Simple method to get cookie from header for Rust |
homepage | |
repository | https://github.com/Klubuntu/easycookie-rs |
max_upload_size | |
id | 1051302 |
size | 6,152 |
📌 Easy method for get cookie from header
Cookie Value from nr is: "data1"
real 0m3.214s
user 0m1.582s
sys 0m1.040s
Cookie Value is: "data2"
real 0m2.867s
user 0m1.540s
sys 0m1.037s
Run the following Cargo command in your project directory:
cargo add easycookie
Or add the following line to your Cargo.toml:
easycookie = "1.0.3"
use easycookie;
use reqwest;
let example_request = reqwest::get(your_url).await.unwrap();
let headers = example_request.headers();
// Method 1
let cookie_value = easycookie::get_cookie(headers.clone(), "cookie_name").await;
println!("Cookie Value is: {:?}", cookie_value.get_value());
// Method 2
let setup_header = easycookie::set_header(headers.clone()).await;
let get_new_cookie = setup_header.get_cookie("cookie_name").await;
println!("Cookie Value is: {:?}", get_new_cookie.get_value());
// Get 2 Cookies from One header
let resp = reqwest::get("http://webtest.5v.pl/cookie/").await.unwrap();
let header = resp.headers();
let cookie_header = easycookie::set_header(header.clone()).await;
let first_cookie = cookie_header.get_cookie("random").await.get_value();
let second_cookie = cookie_header.get_cookie("random2").await.get_value();
println!("Cookies 1: {:?}, 2: {:?}", first_cookie, second_cookie);
// Get cookie by number position, first from 0;
let cookie_from_nr = setup_header.get_cookie_num(0).await;
println!("Cookie Value from nr is: {:?}", cookie_from_nr.get_value());
// Get List - all cookie names from site;
let cookie_list = setup_header.list_cookies();
println!("{:?}", cookie_list);
:star: Thank you for usage
Pull Requests are welcome