(
method: http_types::Method,
scheme: http_types::Scheme,
authority: &str,
path_with_query: &str,
body: Option<&[u8]>,
additional_headers: Option<&[(String, Vec<u8>)]>,
con
| 31 | } |
| 32 | |
| 33 | pub fn request( |
| 34 | method: http_types::Method, |
| 35 | scheme: http_types::Scheme, |
| 36 | authority: &str, |
| 37 | path_with_query: &str, |
| 38 | body: Option<&[u8]>, |
| 39 | additional_headers: Option<&[(String, Vec<u8>)]>, |
| 40 | connect_timeout: Option<u64>, |
| 41 | first_by_timeout: Option<u64>, |
| 42 | between_bytes_timeout: Option<u64>, |
| 43 | ) -> Result<Response> { |
| 44 | fn header_val(v: &str) -> Vec<u8> { |
| 45 | v.to_string().into_bytes() |
| 46 | } |
| 47 | let headers = http_types::Headers::from_list( |
| 48 | &[ |
| 49 | &[ |
| 50 | ("User-agent".to_string(), header_val("WASI-HTTP/0.0.1")), |
| 51 | ("Content-type".to_string(), header_val("application/json")), |
| 52 | ], |
| 53 | additional_headers.unwrap_or(&[]), |
| 54 | ] |
| 55 | .concat(), |
| 56 | )?; |
| 57 | |
| 58 | let request = http_types::OutgoingRequest::new(headers); |
| 59 | |
| 60 | request |
| 61 | .set_method(&method) |
| 62 | .map_err(|()| anyhow!("failed to set method"))?; |
| 63 | request |
| 64 | .set_scheme(Some(&scheme)) |
| 65 | .map_err(|()| anyhow!("failed to set scheme"))?; |
| 66 | request |
| 67 | .set_authority(Some(authority)) |
| 68 | .map_err(|()| anyhow!("failed to set authority"))?; |
| 69 | request |
| 70 | .set_path_with_query(Some(&path_with_query)) |
| 71 | .map_err(|()| anyhow!("failed to set path_with_query"))?; |
| 72 | |
| 73 | let outgoing_body = request |
| 74 | .body() |
| 75 | .map_err(|_| anyhow!("outgoing request write failed"))?; |
| 76 | |
| 77 | let options = http_types::RequestOptions::new(); |
| 78 | options |
| 79 | .set_connect_timeout(connect_timeout) |
| 80 | .map_err(|()| anyhow!("failed to set connect_timeout"))?; |
| 81 | options |
| 82 | .set_first_byte_timeout(first_by_timeout) |
| 83 | .map_err(|()| anyhow!("failed to set first_byte_timeout"))?; |
| 84 | options |
| 85 | .set_between_bytes_timeout(between_bytes_timeout) |
| 86 | .map_err(|()| anyhow!("failed to set between_bytes_timeout"))?; |
| 87 | let options = Some(options); |
| 88 | |
| 89 | let future_response = outgoing_handler::handle(request, options)?; |
| 90 |
nothing calls this directly
no test coverage detected