From c34606e274912cbf67475bfb34e695146d30322c Mon Sep 17 00:00:00 2001 From: alexlapa <36732824+alexlapa@users.noreply.github.com> Date: Sat, 5 Sep 2020 20:46:38 +0300 Subject: [PATCH] Set Content-Type header when curling webdriver (#2261) (#2301) --- .../cli/src/bin/wasm-bindgen-test-runner/headless.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 1eb6c19b670..89b5252c1c1 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,6 @@ use crate::shell::Shell; use anyhow::{bail, format_err, Context, Error}; -use curl::easy::Easy; +use curl::easy::{Easy, List}; use log::{debug, warn}; use rouille::url::Url; use serde::{Deserialize, Serialize}; @@ -522,6 +522,8 @@ impl Client { 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")?, @@ -561,6 +563,14 @@ 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)?;