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, server): remove runtime cargo feature #2975

Merged
merged 6 commits into from
Sep 15, 2022
Merged
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
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ serde_json = "1.0"
tokio = { version = "1", features = [
"fs",
"macros",
"net",
"io-std",
"io-util",
"rt",
Expand All @@ -79,7 +80,6 @@ full = [
"http1",
"http2",
"server",
"runtime",
]

# HTTP versions
Expand All @@ -90,12 +90,6 @@ http2 = ["h2"]
client = []
server = []

# Tokio support
runtime = [
"tokio/net",
"tokio/rt",
]

# C-API support (currently unstable (no semver))
ffi = ["libc"]

Expand Down
11 changes: 11 additions & 0 deletions benches/support/tokiort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ use std::{
use futures_util::Future;
use hyper::rt::{Sleep, Timer};

#[derive(Clone)]
/// An Executor that uses the tokio runtime.
pub struct TokioExecutor;

impl<F> hyper::rt::Executor<F> for TokioExecutor
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
fn execute(&self, fut: F) {
tokio::task::spawn(fut);
}
}

/// A Timer that uses the tokio runtime.

#[derive(Clone, Debug)]
Expand Down
29 changes: 8 additions & 21 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ use std::error::Error as StdError;
use std::fmt;
use std::marker::PhantomData;
use std::sync::Arc;
#[cfg(feature = "runtime")]
use std::time::Duration;

use http::{Request, Response};
use tokio::io::{AsyncRead, AsyncWrite};

use crate::Recv;
use crate::body::Body;
use super::super::dispatch;
use crate::body::Body;
use crate::common::time::Time;
use crate::common::{
exec::{BoxSendFuture, Exec},
task, Future, Pin, Poll,
};
use crate::proto;
use crate::rt::{Executor, Timer};
use crate::Recv;

/// The sender side of an established connection.
pub struct SendRequest<B> {
Expand Down Expand Up @@ -309,11 +308,6 @@ impl Builder {
/// Pass `None` to disable HTTP2 keep-alive.
///
/// Default is currently disabled.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_interval(
Expand All @@ -330,11 +324,6 @@ impl Builder {
/// be closed. Does nothing if `http2_keep_alive_interval` is disabled.
///
/// Default is 20 seconds.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_timeout(&mut self, timeout: Duration) -> &mut Self {
Expand All @@ -350,11 +339,6 @@ impl Builder {
/// disabled.
///
/// Default is `false`.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_while_idle(&mut self, enabled: bool) -> &mut Self {
Expand Down Expand Up @@ -416,9 +400,12 @@ impl Builder {
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec, opts.timer)
.await?;
Ok((
SendRequest { dispatch: tx.unbound() },
//SendRequest { dispatch: tx },
Connection { inner: (PhantomData, h2) },
SendRequest {
dispatch: tx.unbound(),
},
Connection {
inner: (PhantomData, h2),
},
))
}
}
Expand Down
25 changes: 4 additions & 21 deletions src/client/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! ## Example
//! A simple example that uses the `SendRequest` struct to talk HTTP over a Tokio TCP stream
//! ```no_run
//! # #[cfg(all(feature = "client", feature = "http1", feature = "runtime"))]
//! # #[cfg(all(feature = "client", feature = "http1"))]
//! # mod rt {
//! use bytes::Bytes;
//! use http::{Request, StatusCode};
Expand Down Expand Up @@ -57,7 +57,7 @@ use std::fmt;
#[cfg(not(all(feature = "http1", feature = "http2")))]
use std::marker::PhantomData;
use std::sync::Arc;
#[cfg(all(feature = "runtime", feature = "http2"))]
#[cfg(feature = "http2")]
use std::time::Duration;

use bytes::Bytes;
Expand All @@ -79,8 +79,8 @@ use crate::proto;
use crate::rt::Executor;
#[cfg(feature = "http1")]
use crate::upgrade::Upgraded;
use crate::{Recv, Request, Response};
use crate::{common::time::Time, rt::Timer};
use crate::{Recv, Request, Response};

#[cfg(feature = "http1")]
pub mod http1;
Expand Down Expand Up @@ -121,9 +121,7 @@ pin_project! {
///
/// This is a shortcut for `Builder::new().handshake(io)`.
/// See [`client::conn`](crate::client::conn) for more.
pub async fn handshake<T, B>(
io: T,
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
pub async fn handshake<T, B>(io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: Body + 'static,
Expand Down Expand Up @@ -702,11 +700,6 @@ impl Builder {
/// Pass `None` to disable HTTP2 keep-alive.
///
/// Default is currently disabled.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_interval(
Expand All @@ -723,11 +716,6 @@ impl Builder {
/// be closed. Does nothing if `http2_keep_alive_interval` is disabled.
///
/// Default is 20 seconds.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_timeout(&mut self, timeout: Duration) -> &mut Self {
Expand All @@ -743,11 +731,6 @@ impl Builder {
/// disabled.
///
/// Default is `false`.
///
/// # Cargo Feature
///
/// Requires the `runtime` cargo feature to be enabled.
#[cfg(feature = "runtime")]
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_keep_alive_while_idle(&mut self, enabled: bool) -> &mut Self {
Expand Down
2 changes: 1 addition & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! For a small example program simply fetching a URL, take a look at the
//! [full client example](https://github.com/hyperium/hyper/blob/master/examples/client.rs).

#[cfg(all(test, feature = "runtime"))]
#[cfg(test)]
mod tests;

cfg_feature! {
Expand Down
15 changes: 4 additions & 11 deletions src/common/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub trait ConnStreamExec<F, B: Body>: Clone {

pub(crate) type BoxSendFuture = Pin<Box<dyn Future<Output = ()> + Send>>;

// Either the user provides an executor for background tasks, or we use
// `tokio::spawn`.
// Either the user provides an executor for background tasks, or we panic.
// TODO: with the `runtime`feature, `Exec::Default` used `tokio::spawn`. With the
// removal of the opt-in default runtime, this should be refactored.
#[derive(Clone)]
pub enum Exec {
Default,
Expand All @@ -33,15 +34,7 @@ impl Exec {
{
match *self {
Exec::Default => {
#[cfg(feature = "runtime")]
{
tokio::task::spawn(fut);
}

#[cfg(not(feature = "runtime"))]
{
panic!("executor must be set")
}
panic!("executor must be set");
}
Exec::Executor(ref e) => {
e.execute(Box::pin(fut));
Expand Down
2 changes: 2 additions & 0 deletions src/common/io/rewind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ mod tests {
use bytes::Bytes;
use tokio::io::AsyncReadExt;

#[cfg(not(miri))]
#[tokio::test]
async fn partial_rewind() {
let underlying = [104, 101, 108, 108, 111];
Expand All @@ -135,6 +136,7 @@ mod tests {
assert_eq!(&buf, &underlying);
}

#[cfg(not(miri))]
#[tokio::test]
async fn full_rewind() {
let underlying = [104, 101, 108, 108, 111];
Expand Down
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) mod task;
pub(crate) mod time;
pub(crate) mod watch;

#[cfg(any(feature = "http1", feature = "http2", feature = "runtime"))]
#[cfg(any(feature = "http1", feature = "http2"))]
pub(crate) use self::never::Never;
pub(crate) use self::task::Poll;

Expand Down
3 changes: 0 additions & 3 deletions src/common/time.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::{fmt, sync::Arc};
#[cfg(all(feature = "server", feature = "runtime"))]
use std::{
pin::Pin,
time::{Duration, Instant},
};

#[cfg(all(feature = "server", feature = "runtime"))]
use crate::rt::Sleep;
use crate::rt::Timer;

Expand Down Expand Up @@ -56,7 +54,6 @@ impl<F> Future for HyperTimeout<F> where F: Future {
}
*/

#[cfg(all(feature = "server", feature = "runtime"))]
impl Time {
pub(crate) fn sleep(&self, duration: Duration) -> Box<dyn Sleep + Unpin> {
match *self {
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(super) enum Kind {
#[cfg(all(feature = "tcp", feature = "server"))]
Listen,
/// User took too long to send headers
#[cfg(all(feature = "http1", feature = "server", feature = "runtime"))]
#[cfg(all(feature = "http1", feature = "server"))]
HeaderTimeout,
/// Error while reading a body from connection.
#[cfg(any(feature = "http1", feature = "http2"))]
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Error {
Error::new_user(User::UnexpectedHeader)
}

#[cfg(all(feature = "http1", feature = "server", feature = "runtime"))]
#[cfg(all(feature = "http1", feature = "server"))]
pub(super) fn new_header_timeout() -> Error {
Error::new(Kind::HeaderTimeout)
}
Expand Down Expand Up @@ -370,7 +370,7 @@ impl Error {
Kind::Canceled => "operation was canceled",
#[cfg(all(feature = "server", feature = "tcp"))]
Kind::Listen => "error creating server listener",
#[cfg(all(feature = "http1", feature = "server", feature = "runtime"))]
#[cfg(all(feature = "http1", feature = "server"))]
Kind::HeaderTimeout => "read header from client timeout",
#[cfg(any(feature = "http1", feature = "http2"))]
Kind::Body => "error reading a body from connection",
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
//! - `http2`: Enables HTTP/2 support.
//! - `client`: Enables the HTTP `client`.
//! - `server`: Enables the HTTP `server`.
//! - `runtime`: Enables convenient integration with `tokio`, providing
//! connectors and acceptors for TCP, and a default executor.
//!
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section

Expand Down
Loading