refactor(compat): use pub(super) to remove compat_impl modules
This commit is contained in:
@@ -1,7 +1,84 @@
|
||||
//! Wrappers to build compatibility with the `http` crate.
|
||||
|
||||
pub use super::compat_impl::{
|
||||
CompatFuture,
|
||||
CompatService,
|
||||
NewCompatService
|
||||
};
|
||||
use std::io::{Error as IoError};
|
||||
|
||||
use futures::{Future, Poll};
|
||||
use http;
|
||||
use tokio_service::{NewService, Service};
|
||||
|
||||
use error::Error;
|
||||
use proto::Body;
|
||||
use proto::request::Request;
|
||||
use proto::response::Response;
|
||||
|
||||
/// Wraps a `Future` returning an `http::Response` into
|
||||
/// a `Future` returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct CompatFuture<F> {
|
||||
future: F
|
||||
}
|
||||
|
||||
impl<F, Bd> Future for CompatFuture<F>
|
||||
where F: Future<Item=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Item = Response<Bd>;
|
||||
type Error = Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
self.future.poll()
|
||||
.map(|a| a.map(|res| res.into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a `Service` taking an `http::Request` and returning
|
||||
/// an `http::Response` into a `Service` taking a `hyper::server::Request`,
|
||||
/// and returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct CompatService<S> {
|
||||
service: S
|
||||
}
|
||||
|
||||
pub(super) fn service<S>(service: S) -> CompatService<S> {
|
||||
CompatService { service: service }
|
||||
}
|
||||
|
||||
impl<S, Bd> Service for CompatService<S>
|
||||
where S: Service<Request=http::Request<Body>, Response=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Request = Request;
|
||||
type Response = Response<Bd>;
|
||||
type Error = Error;
|
||||
type Future = CompatFuture<S::Future>;
|
||||
|
||||
fn call(&self, req: Self::Request) -> Self::Future {
|
||||
CompatFuture {
|
||||
future: self.service.call(req.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a `NewService` taking an `http::Request` and returning
|
||||
/// an `http::Response` into a `NewService` taking a `hyper::server::Request`,
|
||||
/// and returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct NewCompatService<S> {
|
||||
new_service: S
|
||||
}
|
||||
|
||||
pub(super) fn new_service<S>(new_service: S) -> NewCompatService<S> {
|
||||
NewCompatService { new_service: new_service }
|
||||
}
|
||||
|
||||
impl<S, Bd> NewService for NewCompatService<S>
|
||||
where S: NewService<Request=http::Request<Body>, Response=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Request = Request;
|
||||
type Response = Response<Bd>;
|
||||
type Error = Error;
|
||||
type Instance = CompatService<S::Instance>;
|
||||
|
||||
fn new_service(&self) -> Result<Self::Instance, IoError> {
|
||||
self.new_service.new_service()
|
||||
.map(service)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
use std::io::{Error as IoError};
|
||||
|
||||
use futures::{Future, Poll};
|
||||
use http;
|
||||
use tokio_service::{NewService, Service};
|
||||
|
||||
use error::Error;
|
||||
use proto::Body;
|
||||
use proto::request::Request;
|
||||
use proto::response::Response;
|
||||
|
||||
/// Wraps a `Future` returning an `http::Response` into
|
||||
/// a `Future` returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct CompatFuture<F> {
|
||||
future: F
|
||||
}
|
||||
|
||||
impl<F, Bd> Future for CompatFuture<F>
|
||||
where F: Future<Item=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Item = Response<Bd>;
|
||||
type Error = Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
self.future.poll()
|
||||
.map(|a| a.map(|res| res.into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a `Service` taking an `http::Request` and returning
|
||||
/// an `http::Response` into a `Service` taking a `hyper::server::Request`,
|
||||
/// and returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct CompatService<S> {
|
||||
service: S
|
||||
}
|
||||
|
||||
pub fn service<S>(service: S) -> CompatService<S> {
|
||||
CompatService { service: service }
|
||||
}
|
||||
|
||||
impl<S, Bd> Service for CompatService<S>
|
||||
where S: Service<Request=http::Request<Body>, Response=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Request = Request;
|
||||
type Response = Response<Bd>;
|
||||
type Error = Error;
|
||||
type Future = CompatFuture<S::Future>;
|
||||
|
||||
fn call(&self, req: Self::Request) -> Self::Future {
|
||||
CompatFuture {
|
||||
future: self.service.call(req.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a `NewService` taking an `http::Request` and returning
|
||||
/// an `http::Response` into a `NewService` taking a `hyper::server::Request`,
|
||||
/// and returning a `hyper::server::Response`.
|
||||
#[derive(Debug)]
|
||||
pub struct NewCompatService<S> {
|
||||
new_service: S
|
||||
}
|
||||
|
||||
pub fn new_service<S>(new_service: S) -> NewCompatService<S> {
|
||||
NewCompatService { new_service: new_service }
|
||||
}
|
||||
|
||||
impl<S, Bd> NewService for NewCompatService<S>
|
||||
where S: NewService<Request=http::Request<Body>, Response=http::Response<Bd>, Error=Error>
|
||||
{
|
||||
type Request = Request;
|
||||
type Response = Response<Bd>;
|
||||
type Error = Error;
|
||||
type Instance = CompatService<S::Instance>;
|
||||
|
||||
fn new_service(&self) -> Result<Self::Instance, IoError> {
|
||||
self.new_service.new_service()
|
||||
.map(service)
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
//! A `Server` is created to listen on a port, parse HTTP requests, and hand
|
||||
//! them off to a `Service`.
|
||||
|
||||
#[cfg(feature = "compat")]
|
||||
mod compat_impl;
|
||||
#[cfg(feature = "compat")]
|
||||
pub mod compat;
|
||||
mod service;
|
||||
@@ -191,7 +189,7 @@ impl<B: AsRef<[u8]> + 'static> Http<B> {
|
||||
Send + Sync + 'static,
|
||||
Bd: Stream<Item=B, Error=::Error>,
|
||||
{
|
||||
self.bind(addr, self::compat_impl::new_service(new_service))
|
||||
self.bind(addr, self::compat::new_service(new_service))
|
||||
}
|
||||
|
||||
/// Bind the provided `addr` and return a server with a shared `Core`.
|
||||
|
||||
@@ -23,7 +23,7 @@ use proto::{self, request, response};
|
||||
#[cfg(feature = "compat")]
|
||||
use proto::Body;
|
||||
#[cfg(feature = "compat")]
|
||||
use super::compat_impl;
|
||||
use super::compat;
|
||||
use super::Http;
|
||||
|
||||
impl<B: AsRef<[u8]> + 'static> Http<B> {
|
||||
@@ -71,7 +71,7 @@ impl<B: AsRef<[u8]> + 'static> Http<B> {
|
||||
I: AsyncRead + AsyncWrite + 'static,
|
||||
{
|
||||
self.bind_server(handle, io, HttpService {
|
||||
inner: compat_impl::service(service),
|
||||
inner: compat::service(service),
|
||||
remote_addr: remote_addr,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user