-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ClientBuilder.default_headers() for wasm32 target (#1084)
- Loading branch information
Showing
12 changed files
with
210 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
// Short example of a POST request with form data. | ||
// | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[tokio::main] | ||
async fn main() { | ||
reqwest::Client::new() | ||
let response = reqwest::Client::new() | ||
.post("http://www.baidu.com") | ||
.form(&[("one", "1")]) | ||
.send() | ||
.await | ||
.unwrap(); | ||
.expect("send"); | ||
println!("Response status {}", response.status()); | ||
} | ||
|
||
// The [cfg(not(target_arch = "wasm32"))] above prevent building the tokio::main function | ||
// for wasm32 target, because tokio isn't compatible with wasm32. | ||
// If you aren't building for wasm32, you don't need that line. | ||
// The two lines below avoid the "'main' function not found" error when building for wasm32 target. | ||
#[cfg(target_arch = "wasm32")] | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
|
||
#[cfg(feature = "__tls")] | ||
#[tokio::test] | ||
async fn test_badssl_modern() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
mod support; | ||
use futures_util::stream::StreamExt; | ||
use support::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
mod support; | ||
use futures_util::stream::StreamExt; | ||
use support::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
mod support; | ||
use support::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
mod support; | ||
use futures_util::stream::StreamExt; | ||
use support::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
use std::convert::Infallible; | ||
use std::future::Future; | ||
use std::net; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
mod support; | ||
use support::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![cfg(target_arch = "wasm32")] | ||
|
||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen_test::*; | ||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
// Use `js_namespace` here to bind `console.log(..)` instead of just | ||
// `log(..)` | ||
#[wasm_bindgen(js_namespace = console)] | ||
fn log(s: &str); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
async fn simple_example() { | ||
let res = reqwest::get("https://hyper.rs") | ||
.await | ||
.expect("http get example"); | ||
log(&format!("Status: {}", res.status())); | ||
|
||
let body = res.text().await.expect("response to utf-8 text"); | ||
log(&format!("Body:\n\n{}", body)); | ||
} |