MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / http_get

Function http_get

crates/openshell-server/tests/auth_endpoint_integration.rs:184–207  ·  view source on GitHub ↗

Make an HTTP/1.1 GET request and return (status, body).

(addr: SocketAddr, uri: &str, headers: &[(&str, &str)])

Source from the content-addressed store, hash-verified

182
183/// Make an HTTP/1.1 GET request and return (status, body).
184async fn http_get(addr: SocketAddr, uri: &str, headers: &[(&str, &str)]) -> (StatusCode, String) {
185 let stream = tokio::net::TcpStream::connect(addr).await.unwrap();
186 let (mut sender, conn) = hyper::client::conn::http1::Builder::new()
187 .handshake(TokioIo::new(stream))
188 .await
189 .unwrap();
190 tokio::spawn(async move {
191 let _ = conn.await;
192 });
193
194 let mut builder = Request::builder().method("GET").uri(uri);
195 for (key, value) in headers {
196 builder = builder.header(*key, *value);
197 }
198 let req = builder.body(Empty::<Bytes>::new()).unwrap();
199 let resp = sender.send_request(req).await.unwrap();
200 let status = resp.status();
201 let body_bytes = http_body_util::BodyExt::collect(resp.into_body())
202 .await
203 .unwrap()
204 .to_bytes();
205 let body = String::from_utf8_lossy(&body_bytes).to_string();
206 (status, body)
207}
208
209// ===========================================================================
210// Tests

Calls 3

connectFunction · 0.85
send_requestMethod · 0.80
spawnFunction · 0.50

Tested by

no test coverage detected