Skip to content

Commit

Permalink
update h3 deps. (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Jan 24, 2024
1 parent 4e1d4ff commit c9f07a7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 97 deletions.
7 changes: 3 additions & 4 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
default = ["http1"]
http1 = ["httparse", "xitca-http/http1"]
http2 = ["h2", "itoa", "xitca-http/http2"]
http3 = ["h3", "h3-quinn", "quinn/tls-rustls", "itoa", "async-stream", "rustls_0dot21", "webpki_roots_0dot25", "http_0dot2"]
http3 = ["h3", "h3-quinn", "quinn/tls-rustls", "itoa", "async-stream", "rustls_0dot21", "webpki_roots_0dot25"]
openssl = ["openssl-crate", "tokio-openssl"]
rustls = ["tokio-rustls", "webpki-roots"]
compress = ["http-encoding"]
Expand Down Expand Up @@ -35,8 +35,8 @@ httparse = { version = "1.8.0", optional = true }
h2 = { version = "0.4", optional = true }

# http/3 support
h3 = { version = "0.0.3", optional = true }
h3-quinn = { version = "0.0.4", optional = true }
h3 = { version = "0.0.4", optional = true }
h3-quinn = { version = "0.0.5", optional = true }
quinn = { version = "0.10", optional = true }
async-stream = { version = "0.3", optional = true }

Expand All @@ -53,7 +53,6 @@ webpki-roots = { version = "0.26", optional = true }
rustls-pki-types = "1"

# http3 temporary exclusive
http_0dot2 = { package = "http", version = "0.2", optional = true }
rustls_0dot21 = { package = "rustls", version = "0.21", optional = true }
webpki_roots_0dot25 = { package = "webpki-roots", version = "0.25", optional = true }

Expand Down
42 changes: 0 additions & 42 deletions client/src/h3/proto/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ where

let is_head_method = *req.method() == Method::HEAD;

let req = http_1_to_0dot2(req.into_parts().0);

let mut stream = stream.send_request(req).await?;

if !is_eof {
Expand All @@ -76,8 +74,6 @@ where

let res = stream.recv_response().await?;

let res = http_0dot2_to_1(res.into_parts().0);

let res = if is_head_method {
res.map(|_| ResponseBody::Eof)
} else {
Expand Down Expand Up @@ -107,41 +103,3 @@ pub(crate) async fn connect(client: &Endpoint, addr: &SocketAddr, hostname: &str

Ok(conn)
}

fn http_1_to_0dot2(mut parts: crate::http::request::Parts) -> http_0dot2::Request<()> {
use http_0dot2::{Method, Request, Uri};

let mut builder = Request::builder()
.method(Method::from_bytes(parts.method.as_str().as_bytes()).unwrap())
.uri(Uri::try_from(parts.uri.to_string().as_str()).unwrap());

let mut last = None;
for (k, v) in parts.headers.drain() {
if k.is_some() {
last = k;
}
let name = last.as_ref().unwrap();
builder = builder.header(name.as_str(), v.as_bytes());
}

builder.body(()).unwrap()
}

fn http_0dot2_to_1(mut parts: http_0dot2::response::Parts) -> Response<()> {
use crate::http::StatusCode;

let mut builder = Response::builder()
.status(StatusCode::from_u16(parts.status.as_u16()).unwrap())
.version(Version::HTTP_3);

let mut last = None;
for (k, v) in parts.headers.drain() {
if k.is_some() {
last = k;
}
let name = last.as_ref().unwrap();
builder = builder.header(name.as_str(), v.as_bytes());
}

builder.body(()).unwrap()
}
5 changes: 5 additions & 0 deletions http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# unreleased

# 0.2.1
## Changed
- update `h3` to `0.0.4`.
- update `h3-quinn` to `0.0.5`.

# 0.2.0
## Changed
- `h1::proto::context::Context::encode_headers` does not want `Extensions` type argument anymore. It also wants `&mut HeaderMap` instead of `HeaderMap` to avoid consuming ownership of it.
Expand Down
9 changes: 4 additions & 5 deletions http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xitca-http"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
license = "Apache-2.0"
description = "http library for xitca"
Expand All @@ -17,7 +17,7 @@ http1 = ["httparse", "itoa", "runtime"]
# http2 specific feature.
http2 = ["h2", "fnv", "futures-util/alloc", "runtime", "slab"]
# http3 specific feature.
http3 = ["xitca-io/http3", "futures-util/alloc", "h3", "h3-quinn", "runtime", "http_0dot2"]
http3 = ["xitca-io/http3", "futures-util/alloc", "h3", "h3-quinn", "runtime"]
# openssl as server side tls.
openssl = ["dep:openssl", "runtime"]
# rustls as server side tls.
Expand Down Expand Up @@ -64,9 +64,8 @@ futures-util = { version = "0.3.17", default-features = false, optional = true }
slab = { version = "0.4", optional = true }

# http/3 support
h3 = { version = "0.0.3", optional = true }
h3-quinn = { version = "0.0.4", optional = true }
http_0dot2 = { package = "http", version = "0.2", optional = true }
h3 = { version = "0.0.4", optional = true }
h3-quinn = { version = "0.0.5", optional = true }

# async runtime support.
tokio = { version = "1.30", features = ["rt", "time"], optional = true }
Expand Down
46 changes: 2 additions & 44 deletions http/src/h3/proto/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ where
Ok(res.map(|bytes| (Bytes::copy_from_slice(bytes.chunk()), stream)))
}));

let req = http_0dot2_to_1(req.into_parts().0);

// Reconstruct Request to attach crate body type.
let req = req.map(|_| {
let body = ReqB::from(RequestBody(body));
Expand Down Expand Up @@ -114,10 +112,8 @@ where
C: SendStream<Bytes>,
ResB: Stream<Item = Result<Bytes, BE>>,
{
let (res, body) = fut.await.map_err(Error::Service)?.into_parts();

let res = http_1_to_0dot2(res);

let (parts, body) = fut.await.map_err(Error::Service)?.into_parts();
let res = Response::from_parts(parts, ());
stream.send_response(res).await?;

let mut body = pin!(body);
Expand All @@ -132,44 +128,6 @@ where
Ok(())
}

fn http_1_to_0dot2(mut res: crate::http::response::Parts) -> http_0dot2::Response<()> {
use http_0dot2::{Response, StatusCode, Version};

let mut builder = Response::builder()
.status(StatusCode::from_u16(res.status.as_u16()).unwrap())
.version(Version::HTTP_3);

let mut last = None;
for (k, v) in res.headers.drain() {
if k.is_some() {
last = k;
}
let name = last.as_ref().unwrap();
builder = builder.header(name.as_str(), v.as_bytes());
}

builder.body(()).unwrap()
}

fn http_0dot2_to_1(mut parts: http_0dot2::request::Parts) -> Request<()> {
use crate::http::{Method, Uri};

let mut builder = Request::builder()
.method(Method::from_bytes(parts.method.as_str().as_bytes()).unwrap())
.uri(Uri::try_from(parts.uri.to_string().as_str()).unwrap());

let mut last = None;
for (k, v) in parts.headers.drain() {
if k.is_some() {
last = k;
}
let name = last.as_ref().unwrap();
builder = builder.header(name.as_str(), v.as_bytes());
}

builder.body(()).unwrap()
}

pin_project! {
struct AsyncStream<F, Arg, Fut>{
callback: F,
Expand Down
5 changes: 4 additions & 1 deletion web/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# unreleased
# unreleased 0.2.2
## Add
- `StateRef` can used for extracting `?Sized` type from application state.

## Change
- update `xitca-http` to `0.2.1`.

# 0.2.1
## Add
- `RateLimit` middleware with optional feature `rate-limit`.
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ serde = ["dep:serde"]
__server = ["xitca-http/runtime", "xitca-server"]

[dependencies]
xitca-http = { version = "0.2", features = ["router"], default-features = false }
xitca-http = { version = "0.2.1", features = ["router"], default-features = false }
xitca-service = { version = "0.1", features = ["alloc", "std"] }
xitca-unsafe-collection = "0.1"

Expand Down

0 comments on commit c9f07a7

Please sign in to comment.