desktop: Handle cookies and Content-Type for HTTP requests
Both of these are handled automatically by the browser in the web backend. This makes the desktop client store cookies between requests (though they are discarded when the desktop player is closed), and set the "Content-Type" header based on the mime-type supplied in the URLRequest.
This commit is contained in:
parent
1886a5d434
commit
25cf77c4a2
|
@ -2222,6 +2222,12 @@ dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httpdate"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime"
|
name = "humantime"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
@ -2414,6 +2420,7 @@ dependencies = [
|
||||||
"event-listener",
|
"event-listener",
|
||||||
"futures-lite",
|
"futures-lite",
|
||||||
"http",
|
"http",
|
||||||
|
"httpdate",
|
||||||
"log",
|
"log",
|
||||||
"mime",
|
"mime",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
@ -26,7 +26,7 @@ webbrowser = "0.8.11"
|
||||||
url = "2.4.1"
|
url = "2.4.1"
|
||||||
arboard = "3.2.1"
|
arboard = "3.2.1"
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
isahc = "1.7.2"
|
isahc = { version = "1.7.2", features = ["cookies"] }
|
||||||
rfd = "0.12.0"
|
rfd = "0.12.0"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
bytemuck = "1.14.0"
|
bytemuck = "1.14.0"
|
||||||
|
|
|
@ -70,6 +70,7 @@ impl ExternalNavigatorBackend {
|
||||||
let proxy = proxy.and_then(|url| url.as_str().parse().ok());
|
let proxy = proxy.and_then(|url| url.as_str().parse().ok());
|
||||||
let builder = HttpClient::builder()
|
let builder = HttpClient::builder()
|
||||||
.proxy(proxy)
|
.proxy(proxy)
|
||||||
|
.cookies()
|
||||||
.redirect_policy(RedirectPolicy::Follow);
|
.redirect_policy(RedirectPolicy::Follow);
|
||||||
|
|
||||||
let client = builder.build().ok().map(Rc::new);
|
let client = builder.build().ok().map(Rc::new);
|
||||||
|
@ -244,6 +245,7 @@ impl NavigatorBackend for ExternalNavigatorBackend {
|
||||||
NavigationMethod::Get => IsahcRequest::get(processed_url.to_string()),
|
NavigationMethod::Get => IsahcRequest::get(processed_url.to_string()),
|
||||||
NavigationMethod::Post => IsahcRequest::post(processed_url.to_string()),
|
NavigationMethod::Post => IsahcRequest::post(processed_url.to_string()),
|
||||||
};
|
};
|
||||||
|
let (body_data, mime) = request.body().clone().unwrap_or_default();
|
||||||
if let Some(headers) = isahc_request.headers_mut() {
|
if let Some(headers) = isahc_request.headers_mut() {
|
||||||
for (name, val) in request.headers().iter() {
|
for (name, val) in request.headers().iter() {
|
||||||
headers.insert(
|
headers.insert(
|
||||||
|
@ -257,9 +259,15 @@ impl NavigatorBackend for ExternalNavigatorBackend {
|
||||||
})?,
|
})?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
headers.insert(
|
||||||
|
"Content-Type",
|
||||||
|
HeaderValue::from_str(&mime).map_err(|e| ErrorResponse {
|
||||||
|
url: processed_url.to_string(),
|
||||||
|
error: Error::FetchError(e.to_string()),
|
||||||
|
})?,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (body_data, _) = request.body().clone().unwrap_or_default();
|
|
||||||
let body = isahc_request.body(body_data).map_err(|e| ErrorResponse {
|
let body = isahc_request.body(body_data).map_err(|e| ErrorResponse {
|
||||||
url: processed_url.to_string(),
|
url: processed_url.to_string(),
|
||||||
error: Error::FetchError(e.to_string()),
|
error: Error::FetchError(e.to_string()),
|
||||||
|
|
Loading…
Reference in New Issue