Skip to content

Commit

Permalink
sync: Disable auto compression when downloading
Browse files Browse the repository at this point in the history
If this causes more issues, we might provide an option for users...
  • Loading branch information
taoky committed Aug 22, 2024
1 parent 3a45860 commit 87e1a89
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{build_client, parser::ListResult, regex_process::ExclusionManager, L
// TODO: clean code
pub fn list(args: &ListArgs, bind_address: Option<String>) -> ! {
let parser = args.parser.build();
let client = build_client!(reqwest::blocking::Client, args, parser, bind_address);
let client = build_client!(reqwest::blocking::Client, args, parser, bind_address, true);
let exclusion_manager = ExclusionManager::new(&args.exclude, &args.include);
// get relative
let upstream = &args.upstream_folder;
Expand Down
13 changes: 10 additions & 3 deletions src/cli/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,26 @@ fn download_handler(
fn sync_threads(args: &SyncArgs, parser: &dyn crate::parser::Parser, thr_context: &ThreadsContext) {
let exclusion_manager = ExclusionManager::new(&args.exclude, &args.include);

// Handling listing
let client = build_client!(
reqwest::blocking::Client,
args,
parser,
thr_context.bind_address.as_ref()
thr_context.bind_address.as_ref(),
// some servers (such as download.zerotier.com) would give you gziped list even if you don't ask for that,
// so just enable auto compression when requesting listing
true
);
// async support
// async support, handling download
let runtime = tokio::runtime::Runtime::new().unwrap();
let async_client = build_client!(
reqwest::Client,
args,
parser,
thr_context.bind_address.as_ref()
thr_context.bind_address.as_ref(),
// auto compression is set to off here, as is known that some servers would wrongly report Content-Encoding for compressed files
// like cloud.centos.org
false
);

let mprogress = MultiProgress::with_draw_target(ProgressDrawTarget::term_like_with_hz(
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn get_version() -> &'static str {
return Box::leak(format!("{} (dirty)", build::SHORT_COMMIT).into_boxed_str());
} else if tag.is_empty() {
return build::SHORT_COMMIT;
} else {
} else {
return tag;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ macro_rules! get_resp_mtime {

#[macro_export]
macro_rules! build_client {
($client: ty, $args: expr, $parser: expr, $bind_address: expr) => {{
($client: ty, $args: expr, $parser: expr, $bind_address: expr, $auto_compress: expr) => {{
let mut builder = <$client>::builder()
.user_agent($args.user_agent.clone())
.local_address($bind_address.map(|x| x.parse::<std::net::IpAddr>().unwrap()));
.local_address($bind_address.map(|x| x.parse::<std::net::IpAddr>().unwrap()))
.gzip($auto_compress)
.brotli($auto_compress)
.deflate($auto_compress);
if !$parser.is_auto_redirect() {
builder = builder.redirect(reqwest::redirect::Policy::none());
}
Expand Down

0 comments on commit 87e1a89

Please sign in to comment.