Skip to content

Commit d6cc0f3

Browse files
committed
Impl new func SessionBuilder::compression
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
1 parent 20ede69 commit d6cc0f3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/builder.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct SessionBuilder {
4949
known_hosts_check: KnownHosts,
5050
control_dir: Option<PathBuf>,
5151
config_file: Option<PathBuf>,
52+
compression: Option<bool>,
5253
}
5354

5455
impl Default for SessionBuilder {
@@ -62,6 +63,7 @@ impl Default for SessionBuilder {
6263
known_hosts_check: KnownHosts::Add,
6364
control_dir: None,
6465
config_file: None,
66+
compression: None,
6567
}
6668
}
6769
}
@@ -137,6 +139,23 @@ impl SessionBuilder {
137139
self
138140
}
139141

142+
/// Enable or disable compression (including stdin, stdout, stderr, data
143+
/// for forwarded TCP and unix-domain connections, sftp and scp
144+
/// connections).
145+
///
146+
/// NOTE that the ssh server can forcibly disable the compression.
147+
///
148+
/// By default, ssh uses configure value set in `~/.ssh/config`.
149+
///
150+
/// If `~/.ssh/config` does not enable compression, then it is disabled
151+
/// by default.
152+
///
153+
/// Defaults to `None`.
154+
pub fn compression(&mut self, compression: bool) -> &mut Self {
155+
self.compression = Some(compression);
156+
self
157+
}
158+
140159
/// Connect to the host at the given `host` over SSH using process impl, which will
141160
/// spawn a new ssh process for each `Child` created.
142161
///
@@ -277,6 +296,12 @@ impl SessionBuilder {
277296
init.arg("-F").arg(config_file);
278297
}
279298

299+
if let Some(compression) = self.compression {
300+
let arg = if compression { "yes" } else { "no" };
301+
302+
init.arg("-o").arg(format!("Compression={}", arg));
303+
}
304+
280305
init.arg(destination);
281306

282307
// we spawn and immediately wait, because the process is supposed to fork.

0 commit comments

Comments
 (0)