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

add ClientBuilder.default_headers() for wasm32 target #1084

Merged
merged 6 commits into from Nov 16, 2020
Merged

add ClientBuilder.default_headers() for wasm32 target #1084

merged 6 commits into from Nov 16, 2020

Conversation

stevelr
Copy link
Contributor

@stevelr stevelr commented Nov 12, 2020

Added ClientBuilder.default_headers to wasm, with a couple unit tests.
To make the wasm32 unit tests not generate a barrage of errors for non-wasm code, I added some #cfg gates to some tests in the tests/ folder. Cargo doesn't support target-specific examples, so I had to disable default build of two of the examples that depend on tokio::test.
Unfortunately this will require adding one more step to your CI actions:

cargo build --examples --features __examples

To run the wasm unit tests, use

wasm-pack test --firefox --headless

Copy link
Owner

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to add the general feature, thanks! A few thoughts inline...

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@stevelr
Copy link
Contributor Author

stevelr commented Nov 12, 2020

partially addresses issue #657

@stevelr
Copy link
Contributor Author

stevelr commented Nov 13, 2020

There's another possible way to address the example builds ..

If we add async-std to the dev-dependencies, this code compiles with and without target=wasm32

fn main() {
    async_std::task::block_on(async {
        reqwest::Client::new()
            .post("http://www.baidu.com")
            .form(&[("one", "1")])
            .send()
            .await
            .unwrap();
    });
}

We could also add a comment to explain that reqwest compiles fine with wasm, it's just tokio runtime that is incompatible.
Let me know if you'd like me to make this change to the examples

Copy link
Contributor Author

@stevelr stevelr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated per your suggestion - examples build automatically now

@seanmonstar seanmonstar merged commit 4fe07d8 into seanmonstar:master Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants