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

feat(client): Implement Tower's Service for Client #1747

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tokio-reactor = { version = "0.1", optional = true }
tokio-tcp = { version = "0.1", optional = true }
tokio-threadpool = { version = "0.1.3", optional = true }
tokio-timer = { version = "0.2", optional = true }
tower-service = "0.2"
want = "0.0.6"

[dev-dependencies]
Expand Down
22 changes: 22 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use futures::sync::oneshot;
use http::{Method, Request, Response, Uri, Version};
use http::header::{HeaderValue, HOST};
use http::uri::Scheme;
use tower_service::Service;

use body::{Body, Payload};
use common::{lazy as hyper_lazy, Lazy};
Expand Down Expand Up @@ -594,6 +595,27 @@ impl<C, B> fmt::Debug for Client<C, B> {
}
}

impl<C, B> Service<Request<B>> for Client<C, B>
where
C: Connect + Sync + 'static,
C::Transport: 'static,
C::Future: 'static,
B: Payload + Send + 'static,
B::Data: Send,
{
type Response = Response<Body>;
type Error = ::Error;
type Future = ResponseFuture;

fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Ok(Async::Ready(()))
}

fn call(&mut self, req: Request<B>) -> Self::Future {
self.request(req)
}
}

/// A `Future` that will resolve to an HTTP Response.
///
/// This is returned by `Client::request` (and `Client::get`).
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate time;
#[cfg(feature = "runtime")] extern crate tokio_tcp;
#[cfg(feature = "runtime")] extern crate tokio_threadpool;
#[cfg(feature = "runtime")] extern crate tokio_timer;
extern crate tower_service;
extern crate want;

#[cfg(all(test, feature = "nightly"))]
Expand Down