Skip to content

Commit

Permalink
Replace curl package into ureq (rustwasm#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 authored Jul 10, 2023
1 parent e13d898 commit 0853bb7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0853bb7

Please sign in to comment.