Skip to content

Commit 8706349

Browse files
authored
Expand and correct docs on procedure_http_request ABI function (#3950)
# Description of Changes Title. # API and ABI breaking changes N/a # Expected complexity level and risk 1 # Testing - [ ] Get @coolreader18 to confirm what I've written here is correct.
1 parent 3910b59 commit 8706349

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

crates/bindings-sys/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,28 @@ pub mod raw {
731731

732732
/// Perform an HTTP request as specified by the buffer `request_ptr[..request_len]`,
733733
/// suspending execution until the request is complete,
734-
/// then return its response via a [`BytesSource`] written to `out`.
734+
/// then return its response details via a [`BytesSource`] written to `out[0]`
735+
/// and its response body via another [`BytesSource`] written to `out[1]`.
735736
///
736737
/// `request_ptr[..request_len]` should store a BSATN-serialized `spacetimedb_lib::http::Request` object
737738
/// containing the details of the request to be performed.
738739
///
739-
/// If the request is successful, a [`BytesSource`] is written to `out`
740-
/// containing a BSATN-encoded `spacetimedb_lib::http::Response` object.
740+
/// `body_ptr[..body_len]` should store a byte array, which will be treated as the body of the request.
741+
/// `body_ptr` should be non-null and within the bounds of linear memory even when `body_len` is 0.
742+
///
743+
/// If the request is successful, a [`BytesSource`] is written to `out[0]`
744+
/// containing a BSATN-encoded `spacetimedb_lib::http::Response` object,
745+
/// another [`BytesSource`] containing the bytes of the response body are written to `out[1]`,
746+
/// and this function returns 0.
747+
///
741748
/// "Successful" in this context includes any connection which results in any HTTP status code,
742749
/// regardless of the specified meaning of that code.
750+
/// This includes HTTP error codes such as 404 Not Found and 500 Internal Server Error.
751+
///
752+
/// If the request fails, a [`BytesSource`] is written to `out[0]`
753+
/// containing a BSATN-encoded [`String`] describing the failure,
754+
/// and this function returns `HTTP_ERROR`.
755+
/// In this case, `out[1]` is not written.
743756
///
744757
/// # Errors
745758
///
@@ -759,6 +772,7 @@ pub mod raw {
759772
/// Traps if:
760773
///
761774
/// - `request_ptr` is NULL or `request_ptr[..request_len]` is not in bounds of WASM memory.
775+
/// - `body_ptr` is NULL or `body_ptr[..body_len]` is not in bounds of WASM memory.
762776
/// - `out` is NULL or `out[..size_of::<RowIter>()]` is not in bounds of WASM memory.
763777
/// - `request_ptr[..request_len]` does not contain a valid BSATN-serialized `spacetimedb_lib::http::Request` object.
764778
#[cfg(feature = "unstable")]

crates/core/src/host/wasmtime/wasm_instance_env.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,19 +1650,28 @@ impl WasmInstanceEnv {
16501650
/// Perform an HTTP request as specified by the buffer `request_ptr[..request_len]`,
16511651
/// suspending execution until the request is complete,
16521652
/// then return its response details via a [`BytesSource`] written to `out[0]`
1653-
/// and its response body via a [`BytesSource`] written to `out[1]`.
1653+
/// and its response body via another [`BytesSource`] written to `out[1]`.
16541654
///
16551655
/// `request_ptr[..request_len]` should store a BSATN-serialized [`spacetimedb_lib::http::Request`] object
16561656
/// containing the details of the request to be performed.
16571657
///
1658-
/// `body_ptr[..body_len]` should store the body of the request to be performed;
1658+
/// `body_ptr[..body_len]` should store a byte array, which will be treated as the body of the request.
1659+
/// `body_ptr` should be non-null and within the bounds of linear memory even when `body_len` is 0.
1660+
///
1661+
/// If the request is successful, a [`BytesSource`] is written to `out[0]`
1662+
/// containing a BSATN-encoded [`spacetimedb_lib::http::Response`] object,
1663+
/// another [`BytesSource`] containing the bytes of the response body are written to `out[1]`,
1664+
/// and this function returns 0.
16591665
///
1660-
/// If the request is successful, a [`BytesSource`] is written to `out`
1661-
/// containing a BSATN-encoded [`spacetimedb_lib::http::Response`] object.
16621666
/// "Successful" in this context includes any connection which results in any HTTP status code,
16631667
/// regardless of the specified meaning of that code.
16641668
/// This includes HTTP error codes such as 404 Not Found and 500 Internal Server Error.
16651669
///
1670+
/// If the request fails, a [`BytesSource`] is written to `out[0]`
1671+
/// containing a BSATN-encoded `String` describing the failure,
1672+
/// and this function returns `HTTP_ERROR`.
1673+
/// In this case, `out[1]` is not written.
1674+
///
16661675
/// # Errors
16671676
///
16681677
/// Returns an error:
@@ -1674,7 +1683,7 @@ impl WasmInstanceEnv {
16741683
/// In this case, `out` is not written.
16751684
/// - `HTTP_ERROR` if an error occurs while executing the HTTP request.
16761685
/// In this case, a [`BytesSource`] is written to `out`
1677-
/// containing a BSATN-encoded [`spacetimedb_lib::http::Error`] object.
1686+
/// containing a BSATN-encoded [`String`].
16781687
///
16791688
/// # Traps
16801689
///
@@ -1683,6 +1692,7 @@ impl WasmInstanceEnv {
16831692
/// - `request_ptr` is NULL or `request_ptr[..request_len]` is not in bounds of WASM memory.
16841693
/// - `body_ptr` is NULL or `body_ptr[..body_len]` is not in bounds of WASM memory.
16851694
/// - `out` is NULL or `out[..size_of::<RowIter>()]` is not in bounds of WASM memory.
1695+
/// - `request_ptr[..request_len]` does not contain a valid BSATN-serialized `spacetimedb_lib::http::Request` object.
16861696
pub fn procedure_http_request<'caller>(
16871697
caller: Caller<'caller, Self>,
16881698
(request_ptr, request_len, body_ptr, body_len, out): (WasmPtr<u8>, u32, WasmPtr<u8>, u32, WasmPtr<u32>),

crates/lib/src/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `SpacetimeType`-ified HTTP request, response and error types,
1+
//! `SpacetimeType`-ified HTTP request and response types,
22
//! for use in the procedure HTTP API.
33
//!
44
//! The types here are all mirrors of various types within the `http` crate.

0 commit comments

Comments
 (0)