Skip to content

WIP: Add HTTP/3 support #3925

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

Draft
wants to merge 1 commit into
base: quic
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ futures-channel = { version = "0.3", optional = true }
futures-core = { version = "0.3.31", optional = true }
futures-util = { version = "0.3", default-features = false, features = ["alloc"], optional = true }
h2 = { version = "0.4.2", optional = true }
h3 = { version = "0.0.8", optional = true }
http-body-util = { version = "0.1", optional = true }
httparse = { version = "1.9", optional = true }
httpdate = { version = "1.0", optional = true }
Expand Down Expand Up @@ -69,7 +70,7 @@ tokio-util = "0.7.10"

[features]
# Nothing by default
default = []
default = ["http3", "server"]

# Easily turn it all on
full = [
Expand All @@ -82,6 +83,7 @@ full = [
# HTTP versions
http1 = ["dep:atomic-waker", "dep:futures-channel", "dep:futures-core", "dep:httparse", "dep:itoa", "dep:pin-utils"]
http2 = ["dep:futures-channel", "dep:futures-core", "dep:h2"]
http3 = ["dep:h3"]

# Client/Server
client = ["dep:want", "dep:pin-project-lite", "dep:smallvec"]
Expand Down
2 changes: 1 addition & 1 deletion src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ macro_rules! cfg_proto {
($($item:item)*) => {
cfg_feature! {
#![all(
any(feature = "http1", feature = "http2"),
any(feature = "http1", feature = "http2", feature = "http3"),
any(feature = "client", feature = "server"),
)]
$($item)*
Expand Down
1 change: 1 addition & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) mod either;
#[cfg(any(
all(feature = "client", any(feature = "http1", feature = "http2")),
all(feature = "server", feature = "http1"),
all(feature = "server", feature = "http3"),
))]
pub(crate) mod future;
pub(crate) mod io;
Expand Down
165 changes: 165 additions & 0 deletions src/proto/h3/glue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
use std::task::{Context, Poll};

use bytes::Buf;

pub(super) struct Conn<Q>(Q);

pub(super) struct BidiStream<S>(S);
pub(super) struct SendStream<S>(S);
pub(super) struct RecvStream<S>(S);

impl<Q, B> h3::quic::Connection<B> for Conn<Q>
where
Q: crate::rt::quic::Connection<B>,
B: Buf,
{
type RecvStream = RecvStream<Q::RecvStream>;
type OpenStreams = Self;

fn poll_accept_recv(&mut self, _cx: &mut Context<'_>)
-> Poll<Result<Self::RecvStream, h3::quic::ConnectionErrorIncoming>>
{
todo!();
}

fn poll_accept_bidi(&mut self, _cx: &mut Context<'_>)
-> Poll<Result<Self::BidiStream, h3::quic::ConnectionErrorIncoming>>
{
todo!();
}

fn opener(&self) -> Self::OpenStreams {
todo!();
}
}

impl<Q, B> h3::quic::OpenStreams<B> for Conn<Q>
where
Q: crate::rt::quic::Connection<B>,
B: Buf,
{
type BidiStream = BidiStream<Q::BidiStream>;
type SendStream = SendStream<Q::SendStream>;

fn poll_open_send(&mut self, _cx: &mut Context<'_>)
-> Poll<Result<Self::SendStream, h3::quic::StreamErrorIncoming>>
{
todo!();
}

fn poll_open_bidi(&mut self, _cx: &mut Context<'_>)
-> Poll<Result<Self::BidiStream, h3::quic::StreamErrorIncoming>>
{
todo!();
}

fn close(&mut self, _: h3::error::Code, _: &[u8]) {

}
}

impl<S, B> h3::quic::SendStream<B> for BidiStream<S>
where
S: crate::rt::quic::SendStream<B>,
B: Buf,
{
// Required methods
fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), h3::quic::StreamErrorIncoming>> {
todo!();
}
fn send_data<T: Into<h3::quic::WriteBuf<B>>>(
&mut self,
data: T,
) -> Result<(), h3::quic::StreamErrorIncoming> {
todo!();
}
fn poll_finish(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), h3::quic::StreamErrorIncoming>> {
todo!();
}
fn reset(&mut self, reset_code: u64) {
todo!();
}
fn send_id(&self) -> h3::quic::StreamId {
todo!()
}
}

impl<S, B> h3::quic::SendStream<B> for SendStream<S>
where
S: crate::rt::quic::SendStream<B>,
B: Buf,
{
// Required methods
fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), h3::quic::StreamErrorIncoming>> {
todo!();
}
fn send_data<T: Into<h3::quic::WriteBuf<B>>>(
&mut self,
data: T,
) -> Result<(), h3::quic::StreamErrorIncoming> {
todo!();
}
fn poll_finish(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), h3::quic::StreamErrorIncoming>> {
todo!();
}
fn reset(&mut self, reset_code: u64) {
todo!();
}
fn send_id(&self) -> h3::quic::StreamId {
todo!()
}
}

impl<S> h3::quic::RecvStream for BidiStream<S>
where
S: crate::rt::quic::RecvStream,
{
type Buf = S::Buf;

// Required methods
fn poll_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Self::Buf>, h3::quic::StreamErrorIncoming>> {
todo!();
}
fn stop_sending(&mut self, error_code: u64) {
todo!();
}
fn recv_id(&self) -> h3::quic::StreamId {
todo!();
}
}

impl<S> h3::quic::RecvStream for RecvStream<S>
where
S: crate::rt::quic::RecvStream,
{
type Buf = S::Buf;

// Required methods
fn poll_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Self::Buf>, h3::quic::StreamErrorIncoming>> {
todo!();
}
fn stop_sending(&mut self, error_code: u64) {
todo!();
}
fn recv_id(&self) -> h3::quic::StreamId {
todo!();
}
}
34 changes: 34 additions & 0 deletions src/proto/h3/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use bytes::Buf;
use h3::server::Connection;

use pin_project_lite::pin_project;

mod glue;

pin_project! {
pub(crate) struct Server<Q, S, B, E>
where
Q: crate::rt::quic::Connection<B>,
B: Buf,
{
exec: E,
q: Connection<glue::Conn<Q>, B>,
s: S,
}
}

impl<Q, S, B, E> Future for Server<Q, S, B, E>
where
Q: crate::rt::quic::Connection<B>,
B: Buf,
{
type Output = crate::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
todo!()
}
}
3 changes: 3 additions & 0 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ cfg_feature! {
#[cfg(feature = "http2")]
pub(crate) mod h2;

#[cfg(feature = "http3")]
pub(crate) mod h3;

/// An Incoming Message head. Includes request/status line, and headers.
#[cfg(feature = "http1")]
#[derive(Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion src/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod bounds;
mod io;
mod timer;

#[cfg(hyper_unstable_quic)]
//#[cfg(hyper_unstable_quic)]
#[cfg_attr(docsrs, doc(cfg(hyper_unstable_quic)))]
pub mod quic;

Expand Down
58 changes: 58 additions & 0 deletions src/server/conn/http3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! HTTP/3 Server Connections

use std::error::Error as StdError;

use pin_project_lite::pin_project;

use crate::body::{Body, Incoming as IncomingBody};
use crate::rt::quic;
use crate::service::HttpService;

pin_project! {
/// A Future representing an HTTP/3 connection.
#[must_use = "futures do nothing unless polled"]
pub struct Connection<Q, S, E> {
_i: (Q, S, E),
}
}

/// A configuration builder for HTTP/3 server connections.
///
/// **Note**: The default values of options are *not considered stable*. They
/// are subject to change at any time.
#[derive(Clone, Debug)]
pub struct Builder<E> {
exec: E,
}

// ===== impl Connection =====

// ===== impl Builder =====

impl<E> Builder<E> {
/// Create a new connection builder.
pub fn new(exec: E) -> Self {
Self {
exec,
}
}

/// Bind a connection together with a [`Service`](crate::service::Service).
///
/// This returns a Future that must be polled in order for HTTP to be
/// driven on the connection.
pub fn serve_connection<S, Q, Bd>(&self, quic: Q, service: S) -> Connection<Q, S, E>
where
S: HttpService<IncomingBody, ResBody = Bd>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bd: Body + 'static,
Bd::Error: Into<Box<dyn StdError + Send + Sync>>,
Q: quic::Connection<Bd>,
//E: Http2ServerConnExec<S::Future, Bd>,
E: Clone,
{
Connection {
_i: (quic, service, self.exec.clone()),
}
}
}
2 changes: 2 additions & 0 deletions src/server/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
pub mod http1;
#[cfg(feature = "http2")]
pub mod http2;
//#[cfg(feature = "http3")]
pub mod http3;
Loading