-
Notifications
You must be signed in to change notification settings - Fork 10
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
Improve examples #31
Improve examples #31
Conversation
examples/cookies_load.rs
Outdated
let mut header_map = HeaderMap::new(); | ||
header_map.append( | ||
"Cookie", | ||
HeaderValue::from_str( | ||
&"auth=[AUTH_COOKIE_HERE]; twoFactorAuth=[TWO_FACTOR_AUTH_COOKIE_HERE]", | ||
) | ||
.unwrap(), | ||
); | ||
|
||
config.client = reqwest::Client::builder() | ||
.cookie_store(true) | ||
.default_headers(header_map) | ||
.build() | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The better way to do this would be to create a cookie jar (similarly to cookie_store), and insert the required values before setting it as a cookie_provider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what I'd do:
let mut jar = reqwest::cookie::Jar::default();
use std::str::FromStr;
jar.set_cookies(&mut [HeaderValue::from_str(
&"auth=[AUTH_COOKIE_HERE]; twoFactorAuth=[TWO_FACTOR_AUTH_COOKIE_HERE]",
)], &url::Url::from_str("https://api.vrchat.cloud").expect("Url not okay"));
let jar = Arc::new(jar);
let client = reqwest::Client::builder()
.cookie_provider(jar)
.build()?;
This way the examples for loading and saving cookies could even be combined.
examples/cookies_load.rs
Outdated
let mut header_map = HeaderMap::new(); | ||
header_map.append( | ||
"Cookie", | ||
HeaderValue::from_str( | ||
&"auth=[AUTH_COOKIE_HERE]; twoFactorAuth=[TWO_FACTOR_AUTH_COOKIE_HERE]", | ||
) | ||
.unwrap(), | ||
); | ||
|
||
config.client = reqwest::Client::builder() | ||
.cookie_store(true) | ||
.default_headers(header_map) | ||
.build() | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what I'd do:
let mut jar = reqwest::cookie::Jar::default();
use std::str::FromStr;
jar.set_cookies(&mut [HeaderValue::from_str(
&"auth=[AUTH_COOKIE_HERE]; twoFactorAuth=[TWO_FACTOR_AUTH_COOKIE_HERE]",
)], &url::Url::from_str("https://api.vrchat.cloud").expect("Url not okay"));
let jar = Arc::new(jar);
let client = reqwest::Client::builder()
.cookie_provider(jar)
.build()?;
This way the examples for loading and saving cookies could even be combined.
Okay, github is stupid on that comment. It seems to have duplicated on the website, but when I edit one commit, it edit's both. |
Updated, but I dont think we should merge them, as it would be unclear what is part of the storing and what is part of the loading |
Fair enough. |
No description provided.