Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn committed Nov 28, 2023
1 parent fd566c6 commit 8343528
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where
}
}

// http1_headermap_to_http02 converts an http-1.0 HeaderMap to an http-0.2 HeaderMap.
/// http1_headermap_to_http02 converts an http-1.0 HeaderMap to an http-0.2 HeaderMap.
fn http1_headermap_to_http02(h: http_1::HeaderMap) -> http_02::HeaderMap {
let mut hm = http_02::HeaderMap::new();
for (k, v) in h {
Expand All @@ -186,7 +186,7 @@ fn http1_headermap_to_http02(h: http_1::HeaderMap) -> http_02::HeaderMap {
hm
}

// http02_headermap_to_http1 converts an http-0.2 HeaderMap to an http-1.0 HeaderMap.
/// http02_headermap_to_http1 converts an http-0.2 HeaderMap to an http-1.0 HeaderMap.
fn http02_headermap_to_http1(h: http_02::HeaderMap) -> http_1::HeaderMap {
let mut hm = http_1::HeaderMap::new();
for (k, v) in h {
Expand All @@ -198,8 +198,8 @@ fn http02_headermap_to_http1(h: http_02::HeaderMap) -> http_1::HeaderMap {
hm
}

// http1_request_to_http02 converts an http-1.0 Request to an http-0.2 Request.
// Warning: this conversion is lossy. The Extension field of the request will be lost.
/// http1_request_to_http02 converts an http-1.0 Request to an http-0.2 Request.
/// Warning: this conversion is lossy. The Extension field of the request will be lost.
pub fn http1_request_to_http02<B>(r: http_1::Request<B>) -> http_02::Request<B> {
let (head, body) = r.into_parts();
let mut build = http_02::request::Builder::new()
Expand All @@ -220,8 +220,8 @@ pub fn http1_request_to_http02<B>(r: http_1::Request<B>) -> http_02::Request<B>
build.body(body).unwrap()
}

// http1_response_to_http02 converts an http-1.0 Response to an http-0.2 Response.
// Warning: this conversion is lossy. The Extension field of the response will be lost.
/// http1_response_to_http02 converts an http-1.0 Response to an http-0.2 Response.
/// Warning: this conversion is lossy. The Extension field of the response will be lost.
pub fn http1_response_to_http02<B>(r: http_1::Response<B>) -> http_02::Response<B> {
let (head, body) = r.into_parts();
let mut build = http_02::response::Builder::new()
Expand All @@ -241,8 +241,8 @@ pub fn http1_response_to_http02<B>(r: http_1::Response<B>) -> http_02::Response<
build.body(body).unwrap()
}

// http02_request_to_http1 converts an http-0.2 Request to an http-1.0 Request.
// Warning: this conversion is lossy. The Extension field of the request will be lost.
/// http02_request_to_http1 converts an http-0.2 Request to an http-1.0 Request.
/// Warning: this conversion is lossy. The Extension field of the request will be lost.
pub fn http02_request_to_http1<B>(r: http_02::Request<B>) -> http_1::Request<B> {
let (head, body) = r.into_parts();
let mut build = http_1::request::Builder::new()
Expand All @@ -263,8 +263,8 @@ pub fn http02_request_to_http1<B>(r: http_02::Request<B>) -> http_1::Request<B>
build.body(body).unwrap()
}

// http02_request_to_http1 converts an http-0.2 Response to an http-1.0 Response.
// Warning: this conversion is lossy. The Extension field of the response will be lost.
/// http02_request_to_http1 converts an http-0.2 Response to an http-1.0 Response.
/// Warning: this conversion is lossy. The Extension field of the response will be lost.
pub fn http02_response_to_http1<B>(r: http_02::Response<B>) -> http_1::Response<B> {
let (head, body) = r.into_parts();
let mut build = http_1::response::Builder::new()
Expand Down
14 changes: 10 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::*;

#[tokio::test]
async fn tower_service_03_service_to_hyper_1_service() {
async fn handle<B>(req: http_02::Request<B>) -> Result<http_02::Response<hyper_014::Body>, Infallible>
async fn handle<B>(
req: http_02::Request<B>,
) -> Result<http_02::Response<hyper_014::Body>, Infallible>
where
B: http_body_04::Body,
{
Expand Down Expand Up @@ -57,18 +59,22 @@ async fn tower_service_03_service_to_hyper_1_service() {

#[tokio::test]
async fn hyper_1_service_to_tower_service_03_service() {
async fn handle<B>(req: http_1::Request<B>) -> Result<http_1::Response<http_body_util::Full<Bytes>>, Infallible>
async fn handle<B>(
req: http_1::Request<B>,
) -> Result<http_1::Response<http_body_util::Full<Bytes>>, Infallible>
where
B: http_body_1::Body,
{
let collected = req.into_body().collect().await.unwrap_or_else(|_| panic!());
assert_eq!(collected.to_bytes(), "in");

Ok(http_1::Response::new(http_body_util::Full::new(Bytes::from("out"))))
Ok(http_1::Response::new(http_body_util::Full::new(
Bytes::from("out"),
)))
}

let svc = hyper_1::service::service_fn(handle);
let svc = crate::Hyper1HttpServiceAsTowerService03HttpService::new(svc);
let svc = Hyper1HttpServiceAsTowerService03HttpService::new(svc);

let tcp_listener = std::net::TcpListener::bind("0.0.0.0:0").unwrap();
let addr = tcp_listener.local_addr().unwrap();
Expand Down

0 comments on commit 8343528

Please sign in to comment.