Skip to content

Commit

Permalink
enable gzip by default, introduce --no-gzip flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Andrews committed Jul 15, 2021
1 parent 8f8f3ca commit 2bad5d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## 0.12.2-dev
- enable [`gzip`](https://docs.rs/reqwest/*/reqwest/struct.ClientBuilder.html#method.gzip) support and set Accept-Encoding header by default in the client; disable with `--no-gzip` or `GooseDefault::NoGzip`

## 0.12.1 July 15, 2021
- rename `rustls` feature to `rustls-tls` so `tests/controller.rs` can build with the `rustls` library; update `tungstenite` to `0.14` and `tokio-tungstenite` = `0.15` to allow building with `rustls`
- documentation cleanup; properly rename `GooseDefault::RequestFormat` and fix links
- always configure `GooseConfiguration.manager` and `GooseConfiguration.worker`; confirm Manager is enabled when setting `--expect-workers`
- moved `GooseConfiguration`, `GooseDefault`, and `GooseDefaultType` into new `src/config.rs` file; standardized configuration precedence through internal `GooseConfigure` trait defining `get_value()` for all supported types; general improvements to configuration documentation
- enable [`gzip`](https://docs.rs/reqwest/*/reqwest/struct.ClientBuilder.html#method.gzip) and [`deflate`](https://docs.rs/reqwest/*/reqwest/struct.ClientBuilder.html#method.deflate) support in the client

## 0.12.0 July 8, 2021
- remove internal-only functions and structures from documentation, exposing only what's useful to consumers of the Goose library (API change)
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ rand = "0.8"
regex = "1"
reqwest = { version = "0.11", default-features = false, features = [
"cookies",
"deflate",
"gzip",
"json",
] }
Expand Down
42 changes: 42 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const DEFAULT_PORT: &str = "5115";
/// --websocket-host HOST Sets WebSocket Controller host (default: 0.0.0.0)
/// --websocket-port PORT Sets WebSocket Controller TCP port (default: 5117)
/// --no-autostart Doesn't automatically start load test
/// --no-gzip Doesn't set the gzip Accept-Encoding header
/// --co-mitigation STRATEGY Sets coordinated omission mitigation strategy
/// --throttle-requests VALUE Sets maximum requests per second
/// --sticky-follow Follows base_url redirect with subsequent requests
Expand Down Expand Up @@ -201,6 +202,9 @@ pub struct GooseConfiguration {
/// Doesn't automatically start load test
#[options(no_short)]
pub no_autostart: bool,
/// Doesn't set the gzip Accept-Encoding header
#[options(no_short)]
pub no_gzip: bool,
/// Sets coordinated omission mitigation strategy
#[options(no_short, meta = "STRATEGY")]
pub co_mitigation: Option<GooseCoordinatedOmissionMitigation>,
Expand Down Expand Up @@ -294,6 +298,8 @@ pub(crate) struct GooseDefaults {
pub no_websocket: Option<bool>,
/// An optional default for not auto-starting the load test.
pub no_autostart: Option<bool>,
/// An optional default for not setting the gzip Accept-Encoding header.
pub no_gzip: Option<bool>,
/// An optional default for coordinated omission mitigation.
pub co_mitigation: Option<GooseCoordinatedOmissionMitigation>,
/// An optional default to track additional status code metrics.
Expand Down Expand Up @@ -386,6 +392,8 @@ pub enum GooseDefault {
CoordinatedOmissionMitigation,
/// An optional default for not automatically starting load test.
NoAutoStart,
/// An optional default for not setting the gzip Accept-Encoding header.
NoGzip,
/// An optional default to track additional status code metrics.
StatusCodes,
/// An optional default maximum requests per second.
Expand Down Expand Up @@ -484,6 +492,7 @@ pub enum GooseDefault {
/// - [`GooseDefault::NoTelnet`]
/// - [`GooseDefault::NoWebSocket`]
/// - [`GooseDefault::NoAutoStart`]
/// - [`GooseDefault::NoGzip`]
/// - [`GooseDefault::StatusCodes`]
/// - [`GooseDefault::StickyFollow`]
/// - [`GooseDefault::Manager`]
Expand Down Expand Up @@ -569,6 +578,7 @@ impl GooseDefaultType<&str> for GooseAttack {
| GooseDefault::NoTelnet
| GooseDefault::NoWebSocket
| GooseDefault::NoAutoStart
| GooseDefault::NoGzip
| GooseDefault::StatusCodes
| GooseDefault::StickyFollow
| GooseDefault::Manager
Expand Down Expand Up @@ -655,6 +665,7 @@ impl GooseDefaultType<usize> for GooseAttack {
| GooseDefault::NoTelnet
| GooseDefault::NoWebSocket
| GooseDefault::NoAutoStart
| GooseDefault::NoGzip
| GooseDefault::StatusCodes
| GooseDefault::StickyFollow
| GooseDefault::Manager
Expand Down Expand Up @@ -708,6 +719,7 @@ impl GooseDefaultType<bool> for GooseAttack {
GooseDefault::NoTelnet => self.defaults.no_telnet = Some(value),
GooseDefault::NoWebSocket => self.defaults.no_websocket = Some(value),
GooseDefault::NoAutoStart => self.defaults.no_autostart = Some(value),
GooseDefault::NoGzip => self.defaults.no_gzip = Some(value),
GooseDefault::StatusCodes => self.defaults.status_codes = Some(value),
GooseDefault::StickyFollow => self.defaults.sticky_follow = Some(value),
GooseDefault::Manager => self.defaults.manager = Some(value),
Expand Down Expand Up @@ -800,6 +812,7 @@ impl GooseDefaultType<GooseCoordinatedOmissionMitigation> for GooseAttack {
| GooseDefault::NoTelnet
| GooseDefault::NoWebSocket
| GooseDefault::NoAutoStart
| GooseDefault::NoGzip
| GooseDefault::StatusCodes
| GooseDefault::StickyFollow
| GooseDefault::Manager
Expand Down Expand Up @@ -893,6 +906,7 @@ impl GooseDefaultType<GooseLogFormat> for GooseAttack {
| GooseDefault::NoTelnet
| GooseDefault::NoWebSocket
| GooseDefault::NoAutoStart
| GooseDefault::NoGzip
| GooseDefault::StatusCodes
| GooseDefault::StickyFollow
| GooseDefault::Manager
Expand Down Expand Up @@ -1502,6 +1516,24 @@ impl GooseConfiguration {
])
.unwrap_or(false);

// Configure `no_gzip`.
self.no_gzip = self
.get_value(vec![
// Use --no-gzip if set.
GooseValue {
value: Some(self.no_gzip),
filter: !self.no_gzip,
message: "no_gzip",
},
// Use GooseDefault if not already set and not Worker.
GooseValue {
value: defaults.no_gzip,
filter: defaults.no_gzip.is_none() || self.worker,
message: "no_gzip",
},
])
.unwrap_or(false);

self.co_mitigation = self.get_value(vec![
// Use --co-mitigation if set.
GooseValue {
Expand Down Expand Up @@ -1880,6 +1912,13 @@ impl GooseConfiguration {
detail: "`configuration.no_autostart` can not be set in Worker mode."
.to_string(),
});
// Can't set `no_gzip` on Worker.
} else if self.no_gzip {
return Err(GooseError::InvalidOption {
option: "`configuration.no_gzip`".to_string(),
value: true.to_string(),
detail: "`configuration.no_gzip` can not be set in Worker mode.".to_string(),
});
} else if self
.co_mitigation
.as_ref()
Expand Down Expand Up @@ -2187,6 +2226,8 @@ mod test {
.unwrap()
.set_default(GooseDefault::NoAutoStart, true)
.unwrap()
.set_default(GooseDefault::NoGzip, true)
.unwrap()
.set_default(GooseDefault::ReportFile, report_file.as_str())
.unwrap()
.set_default(GooseDefault::RequestLog, request_log.as_str())
Expand Down Expand Up @@ -2251,6 +2292,7 @@ mod test {
assert!(goose_attack.defaults.no_telnet == Some(true));
assert!(goose_attack.defaults.no_websocket == Some(true));
assert!(goose_attack.defaults.no_autostart == Some(true));
assert!(goose_attack.defaults.no_gzip == Some(true));
assert!(goose_attack.defaults.report_file == Some(report_file));
assert!(goose_attack.defaults.request_log == Some(request_log));
assert!(goose_attack.defaults.request_format == Some(GooseLogFormat::Raw));
Expand Down
8 changes: 3 additions & 5 deletions src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ impl GooseUser {
let client = Client::builder()
.user_agent(APP_USER_AGENT)
.cookie_store(true)
.deflate(true)
.gzip(true)
// Enable gzip unless `--no-gzip` flag is enabled.
.gzip(!configuration.no_gzip)
.build()?;

Ok(GooseUser {
Expand Down Expand Up @@ -1942,8 +1942,7 @@ impl GooseUser {
/// [`.cookie_store(true)`](https://docs.rs/reqwest/*/reqwest/struct.ClientBuilder.html#method.cookie_store).
///
/// In the following example, the Goose client is configured with a different user agent,
/// sets a default header on every request, stores cookies, and supports gzip and deflate
/// compression.
/// sets a default header on every request, stores cookies, and supports gzip compression.
///
/// # Example
/// ```rust
Expand All @@ -1962,7 +1961,6 @@ impl GooseUser {
/// .default_headers(headers)
/// .user_agent("custom user agent")
/// .cookie_store(true)
/// .deflate(true)
/// .gzip(true);
///
/// user.set_client_builder(builder).await?;
Expand Down

0 comments on commit 2bad5d1

Please sign in to comment.