MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / send

Method send

crates/bindings/src/http.rs:486–511  ·  view source on GitHub ↗

Send the HTTP request `request` and wait for its response. For simple `GET` requests with no headers, use [`HttpClient::get`] instead. Include a [`Timeout`] in the [`Request::extensions`] via [`http::request::Builder::extension`] to impose a timeout on the request. All HTTP requests in SpacetimeDB are subject to a maximum timeout of 500 milliseconds. All other extensions in `request` are ignored

(&self, request: http::Request<B>)

Source from the content-addressed store, hash-verified

484 ///
485 /// ```
486 pub fn send<B: Into<Body>>(&self, request: http::Request<B>) -> Result<Response, Error> {
487 let (request, body) = request.map(Into::into).into_parts();
488 let request = convert_request(request);
489 let request = bsatn::to_vec(&request).expect("Failed to BSATN-serialize `spacetimedb_lib::http::Request`");
490
491 match spacetimedb_bindings_sys::procedure::http_request(&request, &body.into_bytes()) {
492 Ok((response_source, body_source)) => {
493 let response = read_bytes_source_as::<st_http::Response>(response_source);
494 let response = convert_response(response).expect("Invalid http response returned from host");
495 let body = if body_source == spacetimedb_bindings_sys::raw::BytesSource::INVALID {
496 // Empty response body — host returns INVALID source for empty bytes
497 Body::from_bytes(Vec::<u8>::new())
498 } else {
499 let mut buf = IterBuf::take();
500 read_bytes_source_into(body_source, &mut buf);
501 Body::from_bytes(buf.clone())
502 };
503
504 Ok(http::Response::from_parts(response, body))
505 }
506 Err(err_source) => {
507 let message = read_bytes_source_as::<String>(err_source);
508 Err(Error { message })
509 }
510 }
511 }
512
513 /// Send a `GET` request to `uri` with no headers and wait for the response.
514 ///

Callers

nothing calls this directly

Calls 14

convert_requestFunction · 0.85
to_vecFunction · 0.85
http_requestFunction · 0.85
convert_responseFunction · 0.85
takeFunction · 0.85
read_bytes_source_intoFunction · 0.85
into_partsMethod · 0.80
from_bytesFunction · 0.50
newFunction · 0.50
OkFunction · 0.50
ErrFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected