Suppose I have a json file like this:
[
{
"name": "session-id",
"value": "235-3769708-3150250",
"domain": ".abc123.com",
"path": "/",
"expires": 1653894983.228494,
"httpOnly": false,
"secure": true
},
{
"name": "ubid-main",
"value": "134-3687901-5787569",
"domain": ".abc123.com",
"path": "/",
"expires": 1653894983.228388,
"httpOnly": false,
"secure": true
},
{
"name": "session-token",
"value": "\"JKASDIUivnisduhfisd213biHUKLFbnoisd2344325\"",
"domain": ".abc123.com",
"path": "/",
"expires": 2082787202.979574,
"httpOnly": false,
"secure": false
}
]
I want to throw all of these cookies in to a request. I have serde-ed the json to a Cookie struct.
And I am building a client like this:
let mut request_headers = header::HeaderMap::new();
request_headers.insert(
header::COOKIE,
header::HeaderValue::from_static("key1=value1;key2=value2;key3=value3"),
);
let client = reqwest::blocking::ClientBuilder::new()
.default_headers(request_headers)
.cookie_store(true)
.build().unwrap();
Which honestly I find it a bit dumb because I have to do something like format!("{:?}={:?};{:?}={:?};{:?}={:?}", key1, value1, key2, value2, key3,value3)
to print the cookie string.
It works, but I mean... kinda not optimal.
Is there any better way?
Thank you.