Skip to content

Commit

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

// 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 @@ -185,6 +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.
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 @@ -196,6 +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.
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 @@ -212,12 +216,12 @@ pub fn http1_request_to_http02<B>(r: http_1::Request<B>) -> http_02::Request<B>
for (k, v) in head.headers {
build = build.header(k.unwrap().as_str(), v.as_ref())
}
// for v in head.extension {
// build = build.extension(v)
// }
// TODO: there is not a way to convert extension over
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.
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 @@ -233,12 +237,12 @@ pub fn http1_response_to_http02<B>(r: http_1::Response<B>) -> http_02::Response<
for (k, v) in head.headers {
build = build.header(k.unwrap().as_str(), v.as_ref())
}
// for v in head.extension {
// build = build.extension(v)
// }
// TODO: there is not a way to convert extension over
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.
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 @@ -255,12 +259,12 @@ pub fn http02_request_to_http1<B>(r: http_02::Request<B>) -> http_1::Request<B>
for (k, v) in head.headers {
build = build.header(k.unwrap().as_str(), v.as_ref())
}
// for v in head.extension {
// build = build.extension(v)
// }
// TODO: there is not a way to convert extension over
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.
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 All @@ -276,8 +280,6 @@ pub fn http02_response_to_http1<B>(r: http_02::Response<B>) -> http_1::Response<
for (k, v) in head.headers {
build = build.header(k.unwrap().as_str(), v.as_ref())
}
// for v in head.extension {
// build = build.extension(v)
// }
// TODO: there is not a way to convert extension over
build.body(body).unwrap()
}

0 comments on commit fd566c6

Please sign in to comment.