Skip to content

Instantly share code, notes, and snippets.

@e00E
Last active July 13, 2017 21:22
Show Gist options
  • Save e00E/d7cd9a8ca98bd66bf74bb79aae455f51 to your computer and use it in GitHub Desktop.
Save e00E/d7cd9a8ca98bd66bf74bb79aae455f51 to your computer and use it in GitHub Desktop.
[package]
name = "failrequest"
version = "0.1.0"
authors = ["e00E"]
[dependencies]
reqwest = { git = "https://github.com/seanmonstar/reqwest.git" }
extern crate reqwest;
const URL: &str = "https://httpbin.org/post";
// uncomment (and comment above) to test http instead of https
// const URL: &str = "http://httpbin.org/post";
fn test_in_memory() {
let body_sizes = &[1usize, 10, 50, 100, 200, 1000];
for &size in body_sizes {
println!("Uploading from memory {}KB", size);
let mut body = Vec::new();
body.resize(size * 1024, 0u8);
let client = reqwest::Client::builder().unwrap()
.gzip(false)
.build().unwrap();
let response = client.post(URL).unwrap()
.body(body)
.send().unwrap();
println!("{}", response.status());
}
}
fn test_with_files() {
// Create the files first with: for i in 1 10 50 100 200 1000; do dd if=/dev/zero of=${i}KB bs=${i}K count=1; done
let filenames = &["1KB", "10KB", "50KB", "100KB", "200KB", "1000KB"];
for filename in filenames {
println!("Uploading from file {}", filename);
let client = reqwest::Client::builder().unwrap()
.gzip(false) // Does not actually change the outcome but I wanted to make sure the body is not altered
// Uncomment to test with Fiddler as proxy on windows
// .proxy(reqwest::Proxy::https("http://localhost:8888").unwrap())
.build().unwrap();
let response = client.post(URL).unwrap()
.body(std::fs::File::open(filename).unwrap())
.send().unwrap();
println!("{}", response.status());
}
}
fn main() {
// Never fails (always status code 200)
test_in_memory();
println!();
// Usually fails starting at 100KB or 200KB on windows
// "fails" means the request "hangs" (it does not finish in the time it should) and
// after a while httpbin returns status code 499 likely because we did not correctly send the request
// Does not fail on windows when http instead of https is used for httpbin
// Does not fail on windows when Fiddler is used to intercept the https traffic
// Does not matter if run in release mode or not
//
// Does not fail on linux
test_with_files();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment