fix: reverse proxy 400 due to duplicate header

This commit is contained in:
DecDuck
2025-07-18 19:36:10 +10:00
parent 2913fdf35b
commit f264600619
3 changed files with 18 additions and 29 deletions
+3 -1
View File
@@ -18,6 +18,7 @@ pub enum RemoteAccessError {
HandshakeFailed(String),
GameNotFound(String),
InvalidResponse(DropServerError),
UnparseableResponse(String),
ManifestDownloadFailed(StatusCode, String),
OutOfSync,
Cache(cacache::Error),
@@ -48,7 +49,8 @@ impl Display for RemoteAccessError {
RemoteAccessError::InvalidEndpoint => write!(f, "invalid drop endpoint"),
RemoteAccessError::HandshakeFailed(message) => write!(f, "failed to complete handshake: {message}"),
RemoteAccessError::GameNotFound(id) => write!(f, "could not find game on server: {id}"),
RemoteAccessError::InvalidResponse(error) => write!(f, "server returned an invalid response: {} {}", error.status_code, error.status_message),
RemoteAccessError::InvalidResponse(error) => write!(f, "server returned an invalid response: {}, {}", error.status_code, error.status_message),
RemoteAccessError::UnparseableResponse(error) => write!(f, "server returned an invalid response: {}", error),
RemoteAccessError::ManifestDownloadFailed(status, response) => write!(
f,
"failed to download game manifest: {status} {response}"
@@ -313,18 +313,9 @@ impl GameDownloadAgent {
match download_game_chunk(context, &self.control_flag, progress_handle, request)
{
Ok(true) => {
debug!(
"Finished context #{} with checksum {}",
index, context.checksum
);
completed_indexes.push(context.checksum.clone());
}
Ok(false) => {
debug!(
"Didn't finish context #{} with checksum {}",
index, context.checksum
);
}
Ok(false) => {}
Err(e) => {
error!("{e}");
sender.send(DownloadManagerSignal::Error(e)).unwrap();
@@ -350,10 +341,7 @@ impl GameDownloadAgent {
.map(|x| {
(
x.checksum.clone(),
context_map_lock
.get(&x.checksum)
.cloned()
.unwrap_or(false),
context_map_lock.get(&x.checksum).cloned().unwrap_or(false),
)
})
.collect::<Vec<(String, bool)>>();
+13 -14
View File
@@ -1,12 +1,14 @@
use crate::client;
use crate::download_manager::util::download_thread_control_flag::{
DownloadThreadControl, DownloadThreadControlFlag,
};
use crate::download_manager::util::progress_object::ProgressHandle;
use crate::error::application_download_error::ApplicationDownloadError;
use crate::error::drop_server_error::DropServerError;
use crate::error::remote_access_error::RemoteAccessError;
use crate::games::downloads::manifest::DropDownloadContext;
use crate::remote::auth::generate_authorization_header;
use log::{debug, warn};
use log::{debug, info, warn};
use md5::{Context, Digest};
use reqwest::blocking::{RequestBuilder, Response};
@@ -40,11 +42,9 @@ impl DropWriter<File> {
// Write automatically pushes to file and hasher
impl Write for DropWriter<File> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.hasher.write_all(buf).map_err(|e| {
io::Error::other(
format!("Unable to write to hasher: {e}"),
)
})?;
self.hasher
.write_all(buf)
.map_err(|e| io::Error::other(format!("Unable to write to hasher: {e}")))?;
self.destination.write(buf)
}
@@ -134,17 +134,11 @@ pub fn download_game_chunk(
progress: ProgressHandle,
request: RequestBuilder,
) -> Result<bool, ApplicationDownloadError> {
debug!(
"Starting download chunk {}, {}, {} #{}",
ctx.file_name, ctx.index, ctx.offset, ctx.checksum
);
// If we're paused
if control_flag.get() == DownloadThreadControlFlag::Stop {
progress.set(0);
return Ok(false);
}
let request = request.header("Authorization", generate_authorization_header());
let response = request
.header("Authorization", generate_authorization_header())
.send()
@@ -152,9 +146,14 @@ pub fn download_game_chunk(
if response.status() != 200 {
debug!("chunk request got status code: {}", response.status());
let err = response.json().unwrap();
let raw_res = response.text().unwrap();
if let Some(err) = serde_json::from_str::<DropServerError>(&raw_res).ok() {
return Err(ApplicationDownloadError::Communication(
RemoteAccessError::InvalidResponse(err),
));
};
return Err(ApplicationDownloadError::Communication(
RemoteAccessError::InvalidResponse(err),
RemoteAccessError::UnparseableResponse(raw_res),
));
}