Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace curl package into ureq #3511

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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`.
Expand Down
16 changes: 13 additions & 3 deletions crates/cli/Cargo.toml
Expand Up @@ -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" }
Expand All @@ -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"]
59 changes: 19 additions & 40 deletions 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};
Expand All @@ -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<String, Json>;
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -318,7 +318,7 @@ an issue against rustwasm/wasm-bindgen!
}

struct Client {
handle: Easy,
agent: Agent,
driver_url: Url,
session: Option<String>,
}
Expand Down Expand Up @@ -548,37 +548,24 @@ impl Client {

fn doit(&mut self, path: &str, method: Method) -> Result<String, Error> {
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)
}
}

Expand All @@ -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: Read>(r: &mut R) -> io::Result<Vec<u8>> {
let mut dst = Vec::new();
r.read_to_end(&mut dst)?;
Expand Down