-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): implement compatibility with http crate
- Loading branch information
1 parent
92595e8
commit 0c7d375
Showing
17 changed files
with
535 additions
and
1 deletion.
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
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,6 @@ | ||
//! Wrappers to build compatibility with the `http` crate. | ||
|
||
pub use super::compat_impl::{ | ||
CompatClient, | ||
CompatFutureResponse | ||
}; |
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,53 @@ | ||
use futures::{Future, Poll, Stream}; | ||
use http_types; | ||
use tokio_service::Service; | ||
|
||
use client::{Connect, Client, FutureResponse}; | ||
use error::Error; | ||
use http::Body; | ||
|
||
/// A Client to make outgoing HTTP requests. | ||
#[derive(Debug)] | ||
pub struct CompatClient<C, B = Body> { | ||
inner: Client<C, B> | ||
} | ||
|
||
pub fn client<C, B>(client: Client<C, B>) -> CompatClient<C, B> { | ||
CompatClient { inner: client } | ||
} | ||
|
||
impl<C, B> Service for CompatClient<C, B> | ||
where C: Connect, | ||
B: Stream<Error=Error> + 'static, | ||
B::Item: AsRef<[u8]>, | ||
{ | ||
type Request = http_types::Request<B>; | ||
type Response = http_types::Response<Body>; | ||
type Error = Error; | ||
type Future = CompatFutureResponse; | ||
|
||
fn call(&self, req: Self::Request) -> Self::Future { | ||
future(self.inner.call(req.into())) | ||
} | ||
} | ||
|
||
/// A `Future` that will resolve to an `http::Response`. | ||
#[must_use = "futures do nothing unless polled"] | ||
#[derive(Debug)] | ||
pub struct CompatFutureResponse { | ||
inner: FutureResponse | ||
} | ||
|
||
pub fn future(fut: FutureResponse) -> CompatFutureResponse { | ||
CompatFutureResponse { inner: fut } | ||
} | ||
|
||
impl Future for CompatFutureResponse { | ||
type Item = http_types::Response<Body>; | ||
type Error = Error; | ||
|
||
fn poll(&mut self) -> Poll<Self::Item, Error> { | ||
self.inner.poll() | ||
.map(|a| a.map(|r| r.into())) | ||
} | ||
} |
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
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
Oops, something went wrong.