Send an HTTP request.
(&self, req: Request<B>)
| 25 | |
| 26 | /// Send an HTTP request. |
| 27 | pub async fn send<B: Into<Body>>(&self, req: Request<B>) -> Result<Response<Body>, Error> { |
| 28 | let (wasi_req, body) = try_into_outgoing(req)?; |
| 29 | let body = body.into(); |
| 30 | let wasi_body = wasi_req.body().unwrap(); |
| 31 | |
| 32 | // 1. Start sending the request head |
| 33 | let res = wasip2::http::outgoing_handler::handle(wasi_req, self.wasi_options()?)?; |
| 34 | |
| 35 | let ((), body) = futures_lite::future::try_zip( |
| 36 | async move { |
| 37 | // 3. send the body: |
| 38 | body.send(wasi_body).await |
| 39 | }, |
| 40 | async move { |
| 41 | // 4. Receive the response |
| 42 | AsyncPollable::new(res.subscribe()).wait_for().await; |
| 43 | |
| 44 | // NOTE: the first `unwrap` is to ensure readiness, the second `unwrap` |
| 45 | // is to trap if we try and get the response more than once. The final |
| 46 | // `?` is to raise the actual error if there is one. |
| 47 | let res = res.get().unwrap().unwrap()?; |
| 48 | try_from_incoming(res) |
| 49 | }, |
| 50 | ) |
| 51 | .await?; |
| 52 | Ok(body) |
| 53 | } |
| 54 | |
| 55 | /// Set timeout on connecting to HTTP server |
| 56 | pub fn set_connect_timeout(&mut self, d: impl Into<Duration>) { |
nothing calls this directly
no test coverage detected