| 34 | |
| 35 | impl HttpClient for ReqwestHttpClient { |
| 36 | fn request( |
| 37 | &self, |
| 38 | req: Request<Full<Bytes>>, |
| 39 | ) -> Pin<Box<dyn Future<Output = Result<BytesResponse, instant_acme::Error>> + Send>> { |
| 40 | let client = self.client.clone(); |
| 41 | Box::pin(async move { |
| 42 | let (parts, body) = req.into_parts(); |
| 43 | let uri = parts.uri.to_string(); |
| 44 | let method = parts.method.clone(); |
| 45 | let body_bytes = body |
| 46 | .collect() |
| 47 | .await |
| 48 | .map_err(|e| { |
| 49 | instant_acme::Error::Other(Box::new(e) as Box<dyn StdError + Send + Sync>) |
| 50 | })? |
| 51 | .to_bytes(); |
| 52 | |
| 53 | tracing::debug!( |
| 54 | target: "certbot::http_client", |
| 55 | %uri, |
| 56 | %method, |
| 57 | request_body_len = body_bytes.len(), |
| 58 | "sending ACME request" |
| 59 | ); |
| 60 | |
| 61 | let mut builder = client.request(parts.method, uri.clone()); |
| 62 | for (name, value) in &parts.headers { |
| 63 | builder = builder.header(name, value); |
| 64 | } |
| 65 | |
| 66 | let response = builder |
| 67 | .body(body_bytes.to_vec()) |
| 68 | .send() |
| 69 | .await |
| 70 | .map_err(|e| { |
| 71 | instant_acme::Error::Other(Box::new(e) as Box<dyn StdError + Send + Sync>) |
| 72 | })?; |
| 73 | |
| 74 | let status = response.status(); |
| 75 | let headers = response.headers().clone(); |
| 76 | let body = response.bytes().await.map_err(|e| { |
| 77 | instant_acme::Error::Other(Box::new(e) as Box<dyn StdError + Send + Sync>) |
| 78 | })?; |
| 79 | |
| 80 | tracing::debug!( |
| 81 | target: "certbot::http_client", |
| 82 | %uri, |
| 83 | %status, |
| 84 | response_body = %String::from_utf8_lossy(&body), |
| 85 | "received ACME response" |
| 86 | ); |
| 87 | |
| 88 | let mut http_response = http::Response::builder().status(status); |
| 89 | for (name, value) in headers { |
| 90 | if let Some(name) = name { |
| 91 | http_response = http_response.header(name, value); |
| 92 | } |
| 93 | } |