Skip to content

Commit 638b1c0

Browse files
committed
Add support for Accept-Encoding header (gzip, deflate, br)
1 parent 5f65adf commit 638b1c0

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Args {
99
pub uri_file: String,
1010
pub user_agent: String,
1111
pub keep_alive: bool,
12+
pub gzip: bool,
1213
pub quiet: bool,
1314
pub progress_bar: bool,
1415
pub captcha_string: String,
@@ -47,6 +48,12 @@ pub fn get_args() -> Args {
4748
.long("no-keep-alive")
4849
.help("Do not use keep-alive"),
4950
)
51+
.arg(
52+
Arg::with_name("no-gzip")
53+
.short("g")
54+
.long("no-gzip")
55+
.help("Do not set 'Accept-Encoding: br,gzip,deflate' header"),
56+
)
5057
.arg(
5158
Arg::with_name("delay")
5259
.short("d")
@@ -131,6 +138,7 @@ pub fn get_args() -> Args {
131138
0
132139
},
133140
cookies: cookies,
141+
gzip: !args.is_present("no-gzip"),
134142
keep_alive: !args.is_present("no-keep-alive"),
135143
quiet: args.is_present("quiet"),
136144
progress_bar: !args.is_present("no-progress-bar") && !args.is_present("quiet"),

src/loader.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use futures::Future;
99
use futures::stream::Stream;
1010

1111
use hyper::{Client, Method, Request, StatusCode, Uri};
12-
use hyper::header::{Cookie, UserAgent};
12+
use hyper::header::{Cookie, UserAgent, AcceptEncoding, Encoding, qitem};
1313
use hyper_tls::HttpsConnector;
1414

1515
use tokio_core::reactor::Core;
@@ -40,6 +40,7 @@ pub struct Loader {
4040
cookie: Cookie,
4141
captcha_string: String,
4242
keep_alive: bool,
43+
gzip: bool,
4344
delay: u64,
4445
}
4546

@@ -95,6 +96,7 @@ impl Loader {
9596
user_agent: user_agent,
9697
cookie: cookie_jar,
9798
keep_alive: args.keep_alive,
99+
gzip: args.gzip,
98100
delay: args.delay,
99101
captcha_string: args.captcha_string.to_string(),
100102
}))
@@ -158,6 +160,13 @@ impl Loader {
158160
let mut req: Request = Request::new(Method::Get, cache_resource.uri.clone());
159161
req.headers_mut().set(self.user_agent.clone());
160162
req.headers_mut().set(self.cookie.clone());
163+
if self.gzip {
164+
req.headers_mut().set(AcceptEncoding(vec![
165+
qitem(Encoding::Brotli),
166+
qitem(Encoding::Gzip),
167+
qitem(Encoding::Deflate),
168+
]));
169+
}
161170

162171
let task = client.request(req).and_then(|res| {
163172
cache_resource.cache_status = match res.headers().get::<XCacheStatus>() {

0 commit comments

Comments
 (0)