From fd566c67c007a7cda1ab365764e2980caa645e65 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 28 Nov 2023 13:31:49 -0800 Subject: [PATCH] add docs --- src/body.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/body.rs b/src/body.rs index 4e84305..63e943e 100644 --- a/src/body.rs +++ b/src/body.rs @@ -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 { @@ -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 { @@ -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(r: http_1::Request) -> http_02::Request { let (head, body) = r.into_parts(); let mut build = http_02::request::Builder::new() @@ -212,12 +216,12 @@ pub fn http1_request_to_http02(r: http_1::Request) -> http_02::Request 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(r: http_1::Response) -> http_02::Response { let (head, body) = r.into_parts(); let mut build = http_02::response::Builder::new() @@ -233,12 +237,12 @@ pub fn http1_response_to_http02(r: http_1::Response) -> 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(r: http_02::Request) -> http_1::Request { let (head, body) = r.into_parts(); let mut build = http_1::request::Builder::new() @@ -255,12 +259,12 @@ pub fn http02_request_to_http1(r: http_02::Request) -> http_1::Request 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(r: http_02::Response) -> http_1::Response { let (head, body) = r.into_parts(); let mut build = http_1::response::Builder::new() @@ -276,8 +280,6 @@ pub fn http02_response_to_http1(r: http_02::Response) -> 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() }