MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / request

Method request

ra-rpc/src/client.rs:158–189  ·  view source on GitHub ↗
(&self, path: &str, body: T)

Source from the content-addressed store, hash-verified

156
157impl RequestClient for RaClient {
158 async fn request<T, R>(&self, path: &str, body: T) -> Result<R, Error>
159 where
160 T: Message + Serialize,
161 R: Message + DeserializeOwned,
162 {
163 let body = serde_json::to_vec(&body).context("Failed to serialize body")?;
164 let url = format!("{}/{}?json", self.remote_uri, path);
165 let response = self
166 .client
167 .post(url)
168 .body(body)
169 .send()
170 .await
171 .context("Failed to send request")?;
172
173 self.try_validate_attestation(&response)
174 .await
175 .context("Failed to validate attestation")?;
176
177 let status = response.status();
178 if !status.is_success() {
179 let body = response.text().await.unwrap_or_default();
180 bail!("Request failed with status={status}, error={body}");
181 }
182 let body = response
183 .bytes()
184 .await
185 .context("Failed to read response")?
186 .to_vec();
187 let response = serde_json::from_slice(&body).context("Failed to deserialize response")?;
188 Ok(response)
189 }
190}

Callers

nothing calls this directly

Calls 5

sendMethod · 0.80
to_vecMethod · 0.80
bytesMethod · 0.80
statusMethod · 0.45

Tested by

no test coverage detected