(request: Request<T>)
| 14 | // TODO: go back and add json stuff??? |
| 15 | |
| 16 | pub(crate) fn try_into_outgoing<T>(request: Request<T>) -> Result<(OutgoingRequest, T), Error> { |
| 17 | let wasi_req = OutgoingRequest::new(header_map_to_wasi(request.headers())?); |
| 18 | |
| 19 | let (parts, body) = request.into_parts(); |
| 20 | |
| 21 | // Set the HTTP method |
| 22 | let method = to_wasi_method(parts.method); |
| 23 | wasi_req |
| 24 | .set_method(&method) |
| 25 | .map_err(|()| anyhow::anyhow!("method rejected by wasi-http: {method:?}"))?; |
| 26 | |
| 27 | // Set the url scheme |
| 28 | let scheme = parts |
| 29 | .uri |
| 30 | .scheme() |
| 31 | .map(to_wasi_scheme) |
| 32 | .unwrap_or(wasip2::http::types::Scheme::Https); |
| 33 | wasi_req |
| 34 | .set_scheme(Some(&scheme)) |
| 35 | .map_err(|()| anyhow::anyhow!("scheme rejected by wasi-http: {scheme:?}"))?; |
| 36 | |
| 37 | // Set authority |
| 38 | let authority = parts.uri.authority().map(Authority::as_str); |
| 39 | wasi_req |
| 40 | .set_authority(authority) |
| 41 | .map_err(|()| anyhow::anyhow!("authority rejected by wasi-http {authority:?}"))?; |
| 42 | |
| 43 | // Set the url path + query string |
| 44 | if let Some(p_and_q) = parts.uri.path_and_query() { |
| 45 | wasi_req |
| 46 | .set_path_with_query(Some(p_and_q.as_str())) |
| 47 | .map_err(|()| anyhow::anyhow!("path and query rejected by wasi-http {p_and_q:?}"))?; |
| 48 | } |
| 49 | |
| 50 | // All done; request is ready for send-off |
| 51 | Ok((wasi_req, body)) |
| 52 | } |
| 53 | |
| 54 | /// This is used by the `http_server` macro. |
| 55 | #[doc(hidden)] |
no test coverage detected