11use super :: {
2- to_internal_error_code,
3- RequestOptionsExtension ,
4- IncomingRequestBody ,
5- IncomingResponseBody ,
6- Request as HttpRequest ,
7- Response as HttpResponse ,
8- body_writer:: BodyWriter ,
2+ body_writer:: BodyWriter , to_internal_error_code, IncomingRequestBody , IncomingResponseBody ,
3+ Request as HttpRequest , RequestOptionsExtension , Response as HttpResponse ,
94} ;
105use crate :: http:: types:: {
11- ErrorCode ,
12- Fields ,
13- HeaderError ,
14- Headers ,
15- Method ,
16- Scheme ,
17- Request as WasiHttpRequest ,
18- Response as WasiHttpResponse ,
19- } ;
20- use std:: {
21- any:: Any ,
22- convert:: TryFrom ,
6+ ErrorCode , Fields , HeaderError , Headers , Method , Request as WasiHttpRequest ,
7+ Response as WasiHttpResponse , Scheme ,
238} ;
9+ use std:: prelude:: v1:: * ;
10+ use std:: { any:: Any , convert:: TryFrom } ;
2411
2512/// Converts a host-side HTTP response (`HttpResponse<T>`) into a WASI HTTP response (`WasiHttpResponse`).
2613///
2714/// This function bridges standard Rust `http` responses with the WASI HTTP model,
2815/// serializing status codes, headers, and body data into their WebAssembly-compatible
2916/// representations. It supports generic response body types and streams the response
3017/// asynchronously into the WASI environment.
31- ///
18+ ///
3219/// # See Also
3320///
3421/// - [`http_from_wasi_response`] — converts a WASI response back into a host-side HTTP response.
@@ -38,7 +25,7 @@ pub fn http_into_wasi_response<T>(mut resp: HttpResponse<T>) -> Result<WasiHttpR
3825where
3926 T : http_body:: Body + Any ,
4027 T :: Data : Into < Vec < u8 > > ,
41- T :: Error : Into < Box < dyn std:: error:: Error + Send + Sync + ' static > >
28+ T :: Error : Into < Box < dyn std:: error:: Error + Send + Sync + ' static > > ,
4229{
4330 if let Some ( incoming_body) = ( & mut resp as & mut dyn Any ) . downcast_mut :: < IncomingResponseBody > ( )
4431 {
5542
5643 let ( body_writer, body_rx, body_result_rx) = BodyWriter :: new ( ) ;
5744
58- let ( response, _future_result) =
59- WasiHttpResponse :: new ( headers, Some ( body_rx) , body_result_rx) ;
45+ let ( response, _future_result) = WasiHttpResponse :: new ( headers, Some ( body_rx) , body_result_rx) ;
6046
6147 _ = response. set_status_code ( resp. status ( ) . as_u16 ( ) ) ;
6248
7460/// This function performs the reverse operation of [`http_into_wasi_response`], translating
7561/// the fields and body of a response from the WASI HTTP model into the conventional Rust
7662/// `http` crate representation.
77- ///
63+ ///
7864/// # See Also
7965///
8066/// - [`http_into_wasi_response`] — the inverse conversion.
@@ -107,10 +93,9 @@ pub fn http_into_wasi_request<T>(mut req: HttpRequest<T>) -> Result<WasiHttpRequ
10793where
10894 T : http_body:: Body + Any ,
10995 T :: Data : Into < Vec < u8 > > ,
110- T :: Error : Into < Box < dyn std:: error:: Error + Send + Sync + ' static > >
96+ T :: Error : Into < Box < dyn std:: error:: Error + Send + Sync + ' static > > ,
11197{
112- if let Some ( incoming_body) = ( & mut req as & mut dyn Any ) . downcast_mut :: < IncomingRequestBody > ( )
113- {
98+ if let Some ( incoming_body) = ( & mut req as & mut dyn Any ) . downcast_mut :: < IncomingRequestBody > ( ) {
11499 if let Some ( request) = incoming_body. take_unstarted ( ) {
115100 return Ok ( request) ;
116101 }
@@ -124,10 +109,7 @@ where
124109 . cloned ( )
125110 . map ( |o| o. 0 ) ;
126111
127- let headers = parts
128- . headers
129- . try_into ( )
130- . map_err ( to_internal_error_code) ?;
112+ let headers = parts. headers . try_into ( ) . map_err ( to_internal_error_code) ?;
131113
132114 let ( body_writer, contents_rx, trailers_rx) = BodyWriter :: new ( ) ;
133115
@@ -161,7 +143,7 @@ where
161143/// from the WASI HTTP model into a conventional Rust `http` request type. It reconstructs
162144/// the URI, method, headers, extensions, and body so that the request can be used directly
163145/// by host HTTP clients, servers, or middleware.
164- ///
146+ ///
165147/// # See Also
166148///
167149/// - [`http_into_wasi_request`] — converts from host HTTP requests into WASI requests.
@@ -185,9 +167,7 @@ pub fn http_from_wasi_request(req: WasiHttpRequest) -> Result<HttpRequest, Error
185167 . map_err ( |_| ErrorCode :: HttpRequestUriInvalid ) ?
186168 } ;
187169
188- let mut builder = http:: Request :: builder ( )
189- . method ( req. get_method ( ) )
190- . uri ( uri) ;
170+ let mut builder = http:: Request :: builder ( ) . method ( req. get_method ( ) ) . uri ( uri) ;
191171
192172 if let Some ( options) = req. get_options ( ) . map ( RequestOptionsExtension ) {
193173 builder = builder. extension ( options) ;
0 commit comments