Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions crates/bindings-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,28 @@ pub mod raw {

/// Perform an HTTP request as specified by the buffer `request_ptr[..request_len]`,
/// suspending execution until the request is complete,
/// then return its response via a [`BytesSource`] written to `out`.
/// then return its response details via a [`BytesSource`] written to `out[0]`
/// and its response body via another [`BytesSource`] written to `out[1]`.
///
/// `request_ptr[..request_len]` should store a BSATN-serialized `spacetimedb_lib::http::Request` object
/// containing the details of the request to be performed.
///
/// If the request is successful, a [`BytesSource`] is written to `out`
/// containing a BSATN-encoded `spacetimedb_lib::http::Response` object.
/// `body_ptr[..body_len]` should store a byte array, which will be treated as the body of the request.
/// `body_ptr` should be non-null and within the bounds of linear memory even when `body_len` is 0.
///
/// If the request is successful, a [`BytesSource`] is written to `out[0]`
/// containing a BSATN-encoded `spacetimedb_lib::http::Response` object,
/// another [`BytesSource`] containing the bytes of the response body are written to `out[1]`,
/// and this function returns 0.
///
/// "Successful" in this context includes any connection which results in any HTTP status code,
/// regardless of the specified meaning of that code.
/// This includes HTTP error codes such as 404 Not Found and 500 Internal Server Error.
///
/// If the request fails, a [`BytesSource`] is written to `out[0]`
/// containing a BSATN-encoded [`String`] describing the failure,
/// and this function returns `HTTP_ERROR`.
/// In this case, `out[1]` is not written.
///
/// # Errors
///
Expand All @@ -762,6 +775,7 @@ pub mod raw {
/// Traps if:
///
/// - `request_ptr` is NULL or `request_ptr[..request_len]` is not in bounds of WASM memory.
/// - `body_ptr` is NULL or `body_ptr[..body_len]` is not in bounds of WASM memory.
/// - `out` is NULL or `out[..size_of::<RowIter>()]` is not in bounds of WASM memory.
/// - `request_ptr[..request_len]` does not contain a valid BSATN-serialized `spacetimedb_lib::http::Request` object.
#[cfg(feature = "unstable")]
Expand Down
20 changes: 15 additions & 5 deletions crates/core/src/host/wasmtime/wasm_instance_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1680,19 +1680,28 @@ impl WasmInstanceEnv {
/// Perform an HTTP request as specified by the buffer `request_ptr[..request_len]`,
/// suspending execution until the request is complete,
/// then return its response details via a [`BytesSource`] written to `out[0]`
/// and its response body via a [`BytesSource`] written to `out[1]`.
/// and its response body via another [`BytesSource`] written to `out[1]`.
///
/// `request_ptr[..request_len]` should store a BSATN-serialized [`spacetimedb_lib::http::Request`] object
/// containing the details of the request to be performed.
///
/// `body_ptr[..body_len]` should store the body of the request to be performed;
/// `body_ptr[..body_len]` should store a byte array, which will be treated as the body of the request.
/// `body_ptr` should be non-null and within the bounds of linear memory even when `body_len` is 0.
///
/// If the request is successful, a [`BytesSource`] is written to `out[0]`
/// containing a BSATN-encoded [`spacetimedb_lib::http::Response`] object,
/// another [`BytesSource`] containing the bytes of the response body are written to `out[1]`,
/// and this function returns 0.
///
/// If the request is successful, a [`BytesSource`] is written to `out`
/// containing a BSATN-encoded [`spacetimedb_lib::http::Response`] object.
/// "Successful" in this context includes any connection which results in any HTTP status code,
/// regardless of the specified meaning of that code.
/// This includes HTTP error codes such as 404 Not Found and 500 Internal Server Error.
///
/// If the request fails, a [`BytesSource`] is written to `out[0]`
/// containing a BSATN-encoded `String` describing the failure,
/// and this function returns `HTTP_ERROR`.
/// In this case, `out[1]` is not written.
///
/// # Errors
///
/// Returns an error:
Expand All @@ -1704,7 +1713,7 @@ impl WasmInstanceEnv {
/// In this case, `out` is not written.
/// - `HTTP_ERROR` if an error occurs while executing the HTTP request.
/// In this case, a [`BytesSource`] is written to `out`
/// containing a BSATN-encoded [`spacetimedb_lib::http::Error`] object.
/// containing a BSATN-encoded [`String`].
///
/// # Traps
///
Expand All @@ -1713,6 +1722,7 @@ impl WasmInstanceEnv {
/// - `request_ptr` is NULL or `request_ptr[..request_len]` is not in bounds of WASM memory.
/// - `body_ptr` is NULL or `body_ptr[..body_len]` is not in bounds of WASM memory.
/// - `out` is NULL or `out[..size_of::<RowIter>()]` is not in bounds of WASM memory.
/// - `request_ptr[..request_len]` does not contain a valid BSATN-serialized `spacetimedb_lib::http::Request` object.
pub fn procedure_http_request<'caller>(
caller: Caller<'caller, Self>,
(request_ptr, request_len, body_ptr, body_len, out): (WasmPtr<u8>, u32, WasmPtr<u8>, u32, WasmPtr<u32>),
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SpacetimeType`-ified HTTP request, response and error types,
//! `SpacetimeType`-ified HTTP request and response types,
//! for use in the procedure HTTP API.
//!
//! The types here are all mirrors of various types within the `http` crate.
Expand Down
Loading