Skip to content

Commit 712fbcf

Browse files
committed
Merge branch 'master' into fix-wasm-compilation
2 parents b68c166 + f50f436 commit 712fbcf

File tree

6 files changed

+19
-31
lines changed

6 files changed

+19
-31
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ jobs:
5252
steps:
5353
- uses: actions/checkout@master
5454

55-
- name: Install stable toolchain
55+
- name: Install nightly toolchain
5656
uses: actions-rs/toolchain@v1
5757
with:
5858
profile: minimal
59-
toolchain: stable
59+
toolchain: nightly
6060
override: true
6161
components: rustfmt
6262

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "http-client"
3-
version = "3.0.0"
3+
version = "4.0.0"
44
license = "MIT OR Apache-2.0"
55
repository = "https://github.com/http-rs/http-client"
66
documentation = "https://docs.rs/http-client"

src/h1.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! http-client implementation for async-h1.
22
3-
use super::{HttpClient, Request, Response};
3+
use super::{Error, HttpClient, Request, Response};
44

55
use async_h1::client;
66
use futures::future::BoxFuture;
7-
use http_types::{Error, StatusCode};
7+
use http_types::StatusCode;
88

99
/// Async-h1 based HTTP Client.
1010
#[derive(Debug)]
@@ -30,9 +30,7 @@ impl Clone for H1Client {
3030
}
3131

3232
impl HttpClient for H1Client {
33-
type Error = Error;
34-
35-
fn send(&self, mut req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
33+
fn send(&self, mut req: Request) -> BoxFuture<'static, Result<Response, Error>> {
3634
Box::pin(async move {
3735
// Insert host
3836
let host = req

src/isahc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! http-client implementation for isahc
22
3-
use super::{Body, HttpClient, Request, Response};
3+
use super::{Body, Error, HttpClient, Request, Response};
44

55
use async_std::io::BufReader;
66
use futures::future::BoxFuture;
@@ -42,9 +42,7 @@ impl Clone for IsahcClient {
4242
}
4343

4444
impl HttpClient for IsahcClient {
45-
type Error = isahc::Error;
46-
47-
fn send(&self, mut req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
45+
fn send(&self, mut req: Request) -> BoxFuture<'static, Result<Response, Error>> {
4846
let client = self.client.clone();
4947
Box::pin(async move {
5048
let mut builder = http::Request::builder()
@@ -65,7 +63,7 @@ impl HttpClient for IsahcClient {
6563
};
6664

6765
let request = builder.body(body).unwrap();
68-
let res = client.send_async(request).await?;
66+
let res = client.send_async(request).await.map_err(Error::from)?;
6967
let (parts, body) = res.into_parts();
7068
let len = body.len().map(|len| len as usize);
7169
let body = Body::from_reader(BufReader::new(body), len);

src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,14 @@ pub use http_types;
4747
/// trait from there together with all existing HTTP client implementations.__
4848
///
4949
/// ## Spawning new request from middleware
50-
/// When threading the trait through a layer of middleware, the middleware must be able to perform
51-
/// new requests. In order to enable this we pass an `HttpClient` instance through the middleware,
52-
/// with a `Clone` implementation. In order to spawn a new request, `clone` is called, and a new
53-
/// request is enabled.
5450
///
55-
/// How `Clone` is implemented is up to the implementors, but in an ideal scenario combining this
56-
/// with the `Client` builder will allow for high connection reuse, improving latency.
57-
pub trait HttpClient: std::fmt::Debug + Unpin + Send + Sync + Clone + 'static {
58-
/// The associated error type.
59-
type Error: Send + Sync + Into<Error>;
60-
51+
/// When threading the trait through a layer of middleware, the middleware must be able to perform
52+
/// new requests. In order to enable this efficiently an `HttpClient` instance may want to be passed
53+
/// though middleware for one of its own requests, and in order to do so should be wrapped in an
54+
/// `Rc`/`Arc` to enable reference cloning.
55+
pub trait HttpClient: std::fmt::Debug + Unpin + Send + Sync + 'static {
6156
/// Perform a request.
62-
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Self::Error>>;
57+
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Error>>;
6358
}
6459

6560
/// The raw body of an http request or response.

src/wasm.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//! http-client implementation for fetch
22
3-
use super::{http_types::Headers, Body, HttpClient, Request, Response};
3+
use super::{http_types::Headers, Body, Error, HttpClient, Request, Response};
44

55
use futures::future::BoxFuture;
66
use futures::prelude::*;
77

88
use std::convert::TryFrom;
9-
use std::io;
109
use std::pin::Pin;
1110
use std::task::{Context, Poll};
1211

@@ -30,9 +29,7 @@ impl Clone for WasmClient {
3029
}
3130

3231
impl HttpClient for WasmClient {
33-
type Error = std::io::Error;
34-
35-
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
32+
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Error>> {
3633
let fut = Box::pin(async move {
3734
let req: fetch::Request = fetch::Request::new(req).await?;
3835
let mut res = req.send().await?;
@@ -54,15 +51,15 @@ impl HttpClient for WasmClient {
5451
}
5552

5653
struct InnerFuture {
57-
fut: Pin<Box<dyn Future<Output = Result<Response, io::Error>> + 'static>>,
54+
fut: Pin<Box<dyn Future<Output = Result<Response, Error>> + 'static>>,
5855
}
5956

6057
// This is safe because WASM doesn't have threads yet. Once WASM supports threads we should use a
6158
// thread to park the blocking implementation until it's been completed.
6259
unsafe impl Send for InnerFuture {}
6360

6461
impl Future for InnerFuture {
65-
type Output = Result<Response, io::Error>;
62+
type Output = Result<Response, Error>;
6663

6764
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
6865
// This is safe because we're only using this future as a pass-through for the inner

0 commit comments

Comments
 (0)