Skip to content

Commit cc852e4

Browse files
committed
Switch to tower_service to be compatible with hyper master
1 parent e92c983 commit cc852e4

File tree

3 files changed

+23
-52
lines changed

3 files changed

+23
-52
lines changed

Cargo.lock

Lines changed: 2 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ conduit-hyper = { git = "https://github.com/jtgeibel/conduit-hyper", branch="asy
8181
futures-preview = { version = "0.3.0-alpha.19", features = ["compat", "async-await"] }
8282
tokio = { version = "0.2.0-alpha.2", default-features = false, features = ["tcp", "fs"]}
8383
tokio-net = { version = "0.2.0-alpha.2", default-features=false, features = ["signal"] }
84-
hyper = { git = "https://github.com/hyperium/hyper", rev = "4920f5e264c57f87dc8b91e7ed9a575359cc093c" }
84+
hyper = { git = "https://github.com/hyperium/hyper" }
8585
ctrlc = { version = "3.0", features = ["termination"] }
8686
indexmap = "1.0.2"
8787
handlebars = "2.0.1"
@@ -91,6 +91,7 @@ conduit-test = "0.8"
9191
hyper-tls = { path = "../../hyperium/hyper-tls" }
9292
lazy_static = "1.0"
9393
diesel_migrations = { version = "1.3.0", features = ["postgres"] }
94+
tower-service = "0.3.0-alpha.1"
9495

9596
[build-dependencies]
9697
dotenv = "0.11"

src/tests/record.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ use std::{
99
pin::Pin,
1010
str,
1111
sync::{Arc, Mutex, Once},
12+
task::{Context, Poll},
1213
thread,
1314
};
1415

1516
use futures::{channel::oneshot, future, prelude::*};
16-
use tokio::{net::TcpListener, runtime::current_thread::Runtime};
17+
use tokio::{
18+
net::{TcpListener, TcpStream},
19+
runtime::current_thread::Runtime,
20+
};
1721

1822
// A "bomb" so when the test task exists we know when to shut down
1923
// the server and fail if the subtask failed.
@@ -149,14 +153,17 @@ struct Proxy {
149153
client: Option<Client>,
150154
}
151155

152-
impl hyper::service::Service for Proxy {
153-
type ReqBody = hyper::Body;
154-
type ResBody = hyper::Body;
156+
impl tower_service::Service<hyper::Request<hyper::Body>> for Proxy {
157+
type Response = hyper::Response<hyper::Body>;
155158
type Error = hyper::Error;
156159
type Future =
157160
Pin<Box<dyn Future<Output = Result<hyper::Response<hyper::Body>, hyper::Error>> + Send>>;
158161

159-
fn call(&mut self, req: hyper::Request<Self::ReqBody>) -> Self::Future {
162+
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
163+
Poll::Ready(Ok(()))
164+
}
165+
166+
fn call(&mut self, req: hyper::Request<hyper::Body>) -> Self::Future {
160167
match *self.record.lock().unwrap() {
161168
Record::Capture(_, _) => {
162169
let client = self.client.as_ref().unwrap().clone();
@@ -176,15 +183,16 @@ impl hyper::service::Service for Proxy {
176183
}
177184
}
178185

179-
impl<Target> hyper::service::MakeService<Target> for Proxy {
180-
type ReqBody = hyper::Body;
181-
type ResBody = hyper::Body;
186+
impl<'a> tower_service::Service<&'a TcpStream> for Proxy {
187+
type Response = Proxy;
182188
type Error = hyper::Error;
183-
type Service = Proxy;
184189
type Future = Pin<Box<dyn Future<Output = Result<Proxy, hyper::Error>> + Send + 'static>>;
185-
type MakeError = hyper::Error;
186190

187-
fn make_service(&mut self, _: Target) -> Self::Future {
191+
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
192+
Poll::Ready(Ok(()))
193+
}
194+
195+
fn call(&mut self, _: &'a TcpStream) -> Self::Future {
188196
Box::pin(future::ok(self.clone()))
189197
}
190198
}

0 commit comments

Comments
 (0)