From 0853bb7fa7727b0cc5a93974449970ce4bbf1970 Mon Sep 17 00:00:00 2001 From: Ho Kim Date: Mon, 10 Jul 2023 23:56:25 +0900 Subject: [PATCH] Replace curl package into ureq (#3511) --- CHANGELOG.md | 3 + crates/cli/Cargo.toml | 16 ++++- .../bin/wasm-bindgen-test-runner/headless.rs | 59 ++++++------------- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e737860770..bdb6a1baad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ because required arguments occurring after optional arguments are currently not supported by the generator. [#3480](https://github.com/rustwasm/wasm-bindgen/pull/3480) +* Replaced `curl` with `ureq`. By default we now use Rustls instead of OpenSSL. + [#3511](https://github.com/rustwasm/wasm-bindgen/pull/3511) + ### Fixed * Fixed bindings and comments for `Atomics.wait`. diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 97d3bc448ba..e01faf1400b 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -16,16 +16,19 @@ default-run = 'wasm-bindgen' rust-version = "1.56" [dependencies] -curl = "0.4.13" docopt = "1.0" env_logger = "0.8" anyhow = "1.0" log = "0.4" -openssl = { version = '0.10.11', optional = true } +native-tls = { version = "0.2", default-features = false, optional = true } rouille = { version = "3.0.0", default-features = false } serde = { version = "1.0", features = ['derive'] } serde_derive = "1.0" serde_json = "1.0" +ureq = { version = "2.7", default-features = false, features = [ + "brotli", + "gzip", +] } walrus = { version = "0.19.0", features = ['parallel'] } wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.87" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.87" } @@ -44,4 +47,11 @@ name = "reference" harness = false [features] -vendored-openssl = ['openssl/vendored'] +default = ["rustls-tls"] + +native-tls = ["ureq/native-tls"] +rustls-tls = ["ureq/tls"] + +# Legacy support +openssl = ["dep:native-tls"] +vendored-openssl = ["openssl", "native-tls/vendored"] diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs index 5cb16040736..7edff27648d 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs @@ -1,6 +1,5 @@ use crate::shell::Shell; use anyhow::{bail, format_err, Context, Error}; -use curl::easy::{Easy, List}; use log::{debug, warn}; use rouille::url::Url; use serde::{Deserialize, Serialize}; @@ -13,6 +12,7 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, Stdio}; use std::thread; use std::time::{Duration, Instant}; +use ureq::Agent; /// Options that can use to customize and configure a WebDriver session. type Capabilities = Map; @@ -98,7 +98,7 @@ pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error ); let mut client = Client { - handle: Easy::new(), + agent: Agent::new(), driver_url, session: None, }; @@ -318,7 +318,7 @@ an issue against rustwasm/wasm-bindgen! } struct Client { - handle: Easy, + agent: Agent, driver_url: Url, session: Option, } @@ -548,37 +548,24 @@ impl Client { fn doit(&mut self, path: &str, method: Method) -> Result { let url = self.driver_url.join(path)?; - self.handle.reset(); - self.handle.url(url.as_str())?; - match method { - Method::Post(data) => { - self.handle.post(true)?; - self.handle - .http_headers(build_headers(&["Content-Type: application/json"]))?; - self.handle.post_fields_copy(data.as_bytes())?; - } - Method::Delete => self.handle.custom_request("DELETE")?, - Method::Get => self.handle.get(true)?, - } - let mut result = Vec::new(); - { - let mut t = self.handle.transfer(); - t.write_function(|buf| { - result.extend_from_slice(buf); - Ok(buf.len()) - })?; - t.perform()? - } - let result = String::from_utf8_lossy(&result); - if self.handle.response_code()? != 200 { - bail!( - "non-200 response code: {}\n{}", - self.handle.response_code()?, - result - ); + let response = match method { + Method::Post(data) => self + .agent + .post(url.as_str()) + .set("Content-Type", "application/json") + .send_bytes(data.as_bytes())?, + Method::Delete => self.agent.delete(url.as_str()).call()?, + Method::Get => self.agent.get(url.as_str()).call()?, + }; + + let response_code = response.status(); + let result = response.into_string()?; + + if response_code != 200 { + bail!("non-200 response code: {}\n{}", response_code, result); } debug!("got: {}", result); - Ok(result.into_owned()) + Ok(result) } } @@ -594,14 +581,6 @@ impl Drop for Client { } } -fn build_headers(headers: &[&str]) -> List { - let mut list = List::new(); - for header in headers { - list.append(header).unwrap(); - } - list -} - fn read(r: &mut R) -> io::Result> { let mut dst = Vec::new(); r.read_to_end(&mut dst)?;