Status: FINAL (corrections and/or clarifications are welcomed)
-
Plugin - a WebAssembly module implementing Proxy-Wasm ABI. There are 3 types of plugins: HTTP, Stream (TCP) and Background task.
-
Host - a proxy or another environment that executes Proxy-Wasm Plugin inside the WebAssembly Virtual Machine (WasmVM).
-
Hostcall - a function call from Plugin to Host.
-
Callback - a function call from Host to Plugin (usually, as a result of an external event).
-
Plugin Context (also known as Root Context) - a context in which operations not related to any specific request or stream are executed.
-
Stream Context - a context in which operations from a specific HTTP request/response pair or TCP stream are executed.
All callbacks (entry points named proxy_on_<event>) are optional,
and are going to be called only if exposed by the Wasm module, and
not restricted by the host due to policy and/or other reasons.
All callbacks, other than the integration and memory management functions, include a unique context identifier as the first parameter, which can be used to distinguish between different contexts.
All functions exposed by the host are required.
All Proxy-Wasm functions exposed by the host return proxy_status_t,
which indicates status of the call (success, invalid memory access,
etc.). Return values are written into memory pointed by return_<value>
parameters.
- params:
- none
- returns:
- none
Function marker used during linking to advertise Wasm module's support for Proxy-Wasm ABI v0.2.1.
This function is never called.
- params:
- none
- returns:
- none
Called when the Wasm module is first loaded.
- params:
i32 (uint32_t) unusedi32 (uint32_t) unused
- returns:
i32 (uint32_t) unused
Warning This is called only if
_initializeis also exported.
Called when the Wasm module is first loaded, after _initialize.
- params:
- none
- returns:
- none
Warning This is called only if
_initializeis not exported.
Called when the Wasm module is first loaded.
- params:
i32 (size_t) memory_size
- returns:
i32 (uint8_t *) memory_data
Called to allocate continuous memory buffer of memory_size using
the in-VM memory allocator.
Plugin must return memory_data pointing to the start of the allocated
memory.
Returning 0 indicates failure.
- params:
i32 (size_t) memory_size
- returns:
i32 (uint8_t *) memory_data
Warning This callback has been deprecated in favor of
proxy_on_memory_allocate, and it's called only in its absence.
Called to allocate continuous memory buffer of memory_size using
the in-VM memory allocator.
Plugin must return memory_data pointing to the start of the allocated
memory.
Returning 0 indicates failure.
- params:
i32 (uint32_t) context_idi32 (uint32_t) parent_context_id
- returns:
- none
Called when the host creates a new context (context_id).
When parent_context_id is 0 then a new plugin context is created,
otherwise a new per-stream context is created and parent_context_id
refers to the plugin context.
- params:
i32 (uint32_t) context_id
- returns:
i32 (bool) completed
Called when the host is done processing context (context_id).
Plugin must return one of the following values:
trueto allow the host to finalize and delete context.falseto indicate that the context is still being used, and that plugin is going to callproxy_donelater to allow the host to finalize and delete that context.
- params:
i32 (uint32_t) context_id
- returns:
- none
Called after the host is done processing context, but before releasing its state.
This can be used e.g. for generating final log entries.
It's called after true was returned from proxy_on_done
or after a call to proxy_done.
- params:
i32 (uint32_t) context_id
- returns:
- none
Called when the host removes the context (context_id) to signal that
the plugin should stop tracking it and remove all associated state.
It's called after true was returned from proxy_on_done
or after a call to proxy_done.
- params:
- none
- returns:
i32 (proxy_status_t) status
Indicates to the host that the plugin is done processing active context.
This should be used after returning false in proxy_on_done.
Returned status value is:
OKon success.NOT_FOUNDwhen active context was not pending finalization.
- params:
i32 (uint32_t) context_id
- returns:
i32 (proxy_status_t) status
Changes the effective context to context_id.
This can be used to change active context, e.g. during
proxy_on_http_call_response, proxy_on_grpc_receive
and/or proxy_on_queue_ready callbacks.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknowncontext_id.
- params:
i32 (uint32_t) unusedi32 (size_t) vm_configuration_size
- returns:
i32 (bool) status
Called when the host starts the WebAssembly Virtual Machine.
Its configuration (of vm_configuration_size) can be retrieved using
proxy_get_buffer_bytes with buffer_id set to VM_CONFIGURATION.
Plugin must return one of the following values:
trueto indicate that the configuration was processed successfully.falseto indicate that the configuration processing failed, and that this instance of WasmVM shouldn't be used.
- params:
i32 (uint32_t) plugin_context_idi32 (size_t) plugin_configuration_size
- returns:
i32 (bool) status
Called when the host starts the Proxy-Wasm plugin.
Its configuration (of plugin_configuration_size) can be retrieved
using proxy_get_buffer_bytes with buffer_id set to
PLUGIN_CONFIGURATION.
Plugin must return one of the following values:
trueto indicate that the configuration was processed successfully.falseto indicate that the configuration processing failed, and that this instance of plugin shouldn't be used.
- params:
i32 (proxy_log_level_t) log_leveli32 (const char *) message_datai32 (size_t) message_size
- returns:
i32 (proxy_status_t) status
Logs message (message_data, message_size) at the log_level.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownlog_level.INVALID_MEMORY_ACCESSwhenmessage_dataand/ormessage_sizepoint to invalid memory address.
- params:
i32 (wasi_fd_id_t) fd_idi32 (wasi_iovec_array_t) ioveci32 (size_t) iovec_sizei32 (size_t *) return_written_bytes
- returns:
i32 (wasi_errno_t) errno
Logs message (iovec, iovec_size).
When fd_id is STDOUT, then it's logged at the INFO level.
When fd_id is STDERR, then it's logged at the ERROR level.
Returned errno value is:
SUCCESSon success.BADFfor unknown or unsupportedfd_id.FAULTwheniovec,iovec_sizeand/orreturn_written_bytespoint to invalid memory address.
- params:
i32 (proxy_log_level_t*) return_log_level
- returns:
i32 (proxy_status_t) status
Retrieves host's current log level (return_log_level).
This can be used to avoid creating log entries that are going to be discarded by the host.
Note Hosts might change the log level at runtime, and currently there is no callback to notify the Wasm module about it, so
return_log_levelcan become stale.
Returned status value is:
OKon success.INVALID_MEMORY_ACCESSwhenreturn_log_levelpoints to invalid memory address.
- params:
i32 (uint64_t *) return_time
- returns:
i32 (proxy_status_t) status
Warning This function has been deprecated in favor of
wasi_snapshot_preview1.clock_time_get.
Retrieves current time (return_time), or the approximation of it.
Note Hosts might return approximate time (e.g. frozen at the context creation) to improve performance and/or prevent various attacks, so consumers shouldn't assume that time changes during callbacks.
Returned status value is:
OKon success.INVALID_MEMORY_ACCESSwhenreturn_timepoints to invalid memory address.
- params:
i32 (wasi_clock_id_t) clock_idi64 (uint64_t) unusedi32 (uint64_t *) return_time
- returns:
i32 (wasi_errno_t) errno
Retrieves current time (return_time), or the approximation of it.
Note Hosts might return approximate time (e.g. frozen at the context creation) to improve performance and/or prevent various attacks, so consumers shouldn't assume that time changes during callbacks.
Returned errno value is:
SUCCESSon success.NOTSUPfor unknown or unsupportedclock_id.FAULTwhenreturn_timepoints to invalid memory address.
- params:
i32 (uint32_t) tick_period
- returns:
i32 (proxy_status_t) status
Sets a low-resolution timer period (tick_period).
When set, the host will call proxy_on_tick every tick_period
milliseconds. Setting tick_period to 0 disables the timer.
Returned status value is:
OKon success.
- params:
i32 (uint32_t) plugin_context_id
- returns:
- none
Called on a timer every tick period.
The tick period can be configured using
proxy_set_tick_period_milliseconds.
- params:
i32 (uint8_t *) bufferi32 (size_t) buffer_size
- returns:
i32 (wasi_errno_t) errno
Generates buffer_size bytes of randomness.
Returned errno value is:
SUCCESSon success.INVALwhen the requestedbuffer_sizeis too large.FAULTwhenbufferand/orbuffer_sizepoint to invalid memory address.
Warning Environment variables should be configured for each plugin. Exposing the host's environment variables is highly discouraged.
- params:
i32 (size_t *) return_num_elementsi32 (size_t *) return_buffer_size
- returns:
i32 (wasi_errno_t) errno
Returns return_num_elements of environment variables, and
return_buffer_size sufficient to serialize them and decorators.
Returned errno value is:
SUCCESSon success.FAULTwhenreturn_num_elementsand/orreturn_buffer_sizepoint to invalid memory address.
- params:
i32 (uint8_t **) return_arrayi32 (uint8_t *) return_buffer
- returns:
i32 (wasi_errno_t) errno
Returns serialized environment variables.
Returned errno value is:
SUCCESSon success.FAULTwhenreturn_arrayand/orreturn_bufferpoint to invalid memory address.
Access to buffers (listed in proxy_buffer_type_t) using functions
in this section is restricted to specific callbacks:
HTTP_REQUEST_BODYcan be read and modified inproxy_on_request_body(or for as long as request processing is paused from it).HTTP_RESPONSE_BODYcan be read and modified inproxy_on_response_body(or for as long as response processing is paused from it).DOWNSTREAM_DATAcan be read and modified inproxy_on_downstream_data(or for as long as upstream processing is paused from it).UPSTREAM_DATAcan be read and modified inproxy_on_downstream_data(or for as long as downstream processing is paused from it).HTTP_CALL_RESPONSE_BODYcan be read inproxy_on_http_call_response.GRPC_CALL_MESSAGEcan be read inproxy_on_grpc_receive.VM_CONFIGURATIONcan be read inproxy_on_vm_start.PLUGIN_CONFIGURATIONcan be read inproxy_on_configure.FOREIGN_FUNCTION_ARGUMENTScan be read inproxy_on_foreign_function.
- params:
i32 (proxy_buffer_type_t) buffer_idi32 (size_t) starti32 (size_t) sizei32 (const uint8_t *) value_datai32 (size_t) value_size
- returns:
i32 (proxy_status_t) status
Sets content of the buffer buffer_id to the provided value
(value_data, value_size) replacing size bytes starting
at start in the existing buffer.
The combination of start and size parameters can be used to perform
prepend (start=0, size=0), append (start larger or equal than the
existing buffer size, may be set to the maximum size_t value), inject
and replace (start smaller than the existing buffer size) operations.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownbuffer_id.NOT_FOUNDwhen the requestedbuffer_idisn't available.INVALID_MEMORY_ACCESSwhenvalue_dataand/orvalue_sizepoint to invalid memory address.
- params:
i32 (proxy_buffer_type_t) buffer_idi32 (size_t) starti32 (size_t) max_sizei32 (uint8_t **) return_value_datai32 (size_t *) return_value_size
- returns:
i32 (proxy_status_t) status
Retrieves up to max_size bytes starting at start from the buffer
buffer_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownbuffer_id, or in case of buffer overflow due to invalidstartand/ormax_sizevalues.NOT_FOUNDwhen the requestedbuffer_idisn't available.INVALID_MEMORY_ACCESSwhenreturned_value_dataand/orreturned_value_sizepoint to invalid memory address.
- params:
i32 (proxy_buffer_type_t) buffer_idi32 (size_t *) return_buffer_sizei32 (uint32_t *) return_unused
- returns:
i32 (proxy_status_t) status
Retrieves size (return_buffer_size) of the buffer buffer_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownbuffer_id.NOT_FOUNDwhen the requestedbuffer_idisn't available.INVALID_MEMORY_ACCESSwhenreturn_buffer_sizeand/orreturn_unusedpoint to invalid memory address.
Access to HTTP fields (listed in proxy_map_type_t) using
functions in this section is restricted to specific callbacks:
HTTP_REQUEST_HEADERScan be read inproxy_on_log, and read and modified fromproxy_on_request_headers(or for as long as request processing is paused from it).HTTP_REQUEST_TRAILERScan be read inproxy_on_log, and read and modified inproxy_on_request_trailers(or for as long as request processing is paused from it). They can be added inproxy_on_request_body, but only when the proxied request doesn't have trailers (end_of_streamistrue).HTTP_RESPONSE_HEADERScan be read inproxy_on_log, and read and modified inproxy_on_response_headers(or for as long as response processing is paused from it).HTTP_RESPONSE_TRAILERScan be read inproxy_on_log, and read and modified inproxy_on_response_trailers(or for as long as response processing is paused from it). They can be added inproxy_on_response_body, but only when the proxied response doesn't have trailers (end_of_streamistrue).GRPC_CALL_INITIAL_METADATAcan be read inproxy_on_grpc_receive_initial_metadata.GRPC_CALL_TRAILING_METADATAcan be read inproxy_on_grpc_receive_trailing_metadata.HTTP_CALL_RESPONSE_HEADERScan be read inproxy_on_http_call_response.HTTP_CALL_RESPONSE_TRAILERScan be read inproxy_on_http_call_response.
- params:
i32 (proxy_map_type_t) map_idi32 (size_t *) return_serialized_pairs_size
- returns:
i32 (proxy_status_t) status
Retrieves size (return_serialized_pairs_size) of all key-value pairs
from the map map_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenreturn_serialized_pairs_sizepoints to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (uint8_t **) return_serialized_pairs_datai32 (size_t *) return_serialized_pairs_size
- returns:
i32 (proxy_status_t) status
Retrieves all key-value pairs from the map map_id.
Returned map (return_serialized_pairs_data,
return_serialized_pairs_size) is serialized.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenreturn_serialized_pairs_dataand/orreturn_serialized_pairs_sizepoint to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (const uint8_t *) serialized_pairs_datai32 (size_t) serialized_pairs_size
- returns:
i32 (proxy_status_t) status
Sets all key-value pairs in the map map_id to the provided
serialized map (serialized_pairs_data, serialized_pairs_size).
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenserialized_pairs_dataand/orserialized_pairs_sizepoint to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (const char *) key_datai32 (size_t) key_sizei32 (uint8_t **) return_value_datai32 (size_t *) return_value_size
- returns:
i32 (proxy_status_t) status
Retrieves value (return_value_data, return_value_size) of the key
(key_data, key_value) from the map map_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.NOT_FOUNDwhen the requested key was not found.INVALID_MEMORY_ACCESSwhenkey_data,key_size,return_value_dataand/orreturn_value_sizepoint to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (const char *) key_datai32 (size_t) key_sizei32 (const uint8_t *) value_datai32 (size_t) value_size
- returns:
i32 (proxy_status_t) status
Adds key (key_data, key_size) with value (value_data,
value_size) to the map map_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenkey_data,key_size,value_dataand/orvalue_sizepoint to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (const char *) key_datai32 (size_t) key_sizei32 (const uint8_t *) value_datai32 (size_t) value_size
- returns:
i32 (proxy_status_t) status
Adds or replaces key's (key_data, key_value) value with the provided
value (value_data, value_size) in the map map_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenkey_data,key_size,value_dataand/orvalue_sizepoint to invalid memory address.
- params:
i32 (proxy_map_type_t) map_idi32 (const char *) key_datai32 (size_t) key_size
- returns:
i32 (proxy_status_t) status
Removes the key (key_data, key_value) from the map map_id.
Returned status value is:
OKon success (including the case when the requested key didn't exist).BAD_ARGUMENTfor unknownmap_id.INVALID_MEMORY_ACCESSwhenkey_dataand/orkey_sizepoint to invalid memory address.
- params:
i32 (proxy_stream_type_t) stream_type
- returns:
i32 (proxy_status_t) status
Resumes processing of paused stream_type.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownstream_type.UNIMPLEMENTEDwhen continuation of the requestedstream_typeis not supported.
- params:
i32 (proxy_stream_type_t) stream_type
- returns:
i32 (proxy_status_t) status
Closes or resets stream_type.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownstream_type.
- params:
i32 (uint32_t *) return_status_codei32 (const char **) return_status_message_datai32 (size_t *) return_status_message_size
- returns:
i32 (proxy_status_t) status
Retrieves status code (return_status_code) and status message
(return_status_message_data, return_status_message_size) of
the HTTP call when called from proxy_on_http_call_response
or gRPC stream or call when called from proxy_on_grpc_close.
Returned status value is:
OKon success.INVALID_MEMORY_ACCESSwhenreturn_status_code,return_status_message_dataand/orreturn_status_message_sizepoint to invalid memory address.
Note
downstreamrefers to the connection between client and proxy,upstreamrefers to the connection between proxy and backend.
Note The same unique
stream_context_idis shared by a pair ofdownstreamandupstreamconnections.
- params:
i32 (uint32_t) stream_context_id
- returns:
i32 (proxy_action_t) action
Called when a new connection is established.
Plugin must return one of the following values:
CONTINUEto allow the new connection to be established.PAUSEto pause processing of the new connection.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) data_sizei32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called for each data chunk received from downstream, even when the processing is paused.
data_size represents the total available size of the data that can be
retrieved, and its value will increment if the processing is paused and
data is buffered by the host and not forwarded upstream.
Data (of data_size) can be retrieved and/or modified using
proxy_get_buffer_bytes and/or proxy_set_buffer_bytes
with buffer_id set to DOWNSTREAM_DATA.
Paused downstream can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
DOWNSTREAM.
Plugin must return one of the following values:
CONTINUEto forwardDOWNSTREAM_DATAbuffer upstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (proxy_peer_type_t) peer_type
- returns:
- none
Called when downstream connection is closed.
The peer_type should describe whether this was initiated by a LOCAL
or REMOTE peer, but this value might also be UNKNOWN.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) data_sizei32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called for each data chunk received from upstream, even when the processing is paused.
data_size represents the total available size of the data that can be
retrieved, and its value will increment if the processing is paused and
data is buffered by the host and not forwarded downstream.
Data (of data_size) can be retrieved and/or modified using
proxy_get_buffer_bytes and/or proxy_set_buffer_bytes
with buffer_id set to UPSTREAM_DATA.
Paused upstream can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
UPSTREAM.
Plugin must return one of the following values:
CONTINUEto forwardUPSTREAM_DATAbuffer downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (proxy_peer_type_t) peer_type
- returns:
- none
Called when upstream connection is closed.
The peer_type should describe whether this was initiated by a LOCAL
or REMOTE peer, but this value might also be UNKNOWN.
Note The same unique
stream_context_idis shared by HTTP request and response.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) num_headersi32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called when HTTP request headers are received from downstream.
All num_headers headers can be retrieved and/or modified using
proxy_get_header_map_pairs and/or proxy_set_header_map_pairs
with map_id set to HTTP_REQUEST_HEADERS.
Individual HTTP request headers can be retrieved and/or modified using
proxy_get_header_map_value, proxy_replace_header_map_value,
proxy_add_header_map_value and/or proxy_remove_header_map_value
with map_id set to HTTP_REQUEST_HEADERS.
Paused HTTP requests can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_REQUEST.
Additionally, instead of forwarding the HTTP request to upstream,
a HTTP response can be sent using proxy_send_local_response.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_REQUEST_HEADERSfields downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) body_sizei32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called for each chunk of HTTP request body received from downstream, even when the processing is paused.
Request body chunk (of body_size) can be retrieved and/or modified
using proxy_get_buffer_bytes and/or proxy_set_buffer_bytes
with buffer_id set to HTTP_REQUEST_BODY.
body_size represents the total available size of the body that can be
retrieved, and its value will increment if the processing is paused and
the body is buffered by the host and not forwarded upstream.
Paused HTTP requests can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_REQUEST.
Additionally, as long as HTTP response headers were not sent downstream,
a HTTP response can be sent using proxy_send_local_response.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_REQUEST_BODYbuffer upstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) num_trailers
- returns:
i32 (proxy_action_t) action
Called when HTTP request trailers are received from downstream.
All num_trailers trailers can be retrieved and/or modified using
proxy_get_header_map_pairs and/or proxy_set_header_map_pairs
with map_id set to HTTP_REQUEST_TRAILERS.
Individual HTTP request trailers can be retrieved and/or modified using
proxy_get_header_map_value, proxy_replace_header_map_value,
proxy_add_header_map_value and/or proxy_remove_header_map_value
with map_id set to HTTP_REQUEST_TRAILERS.
Paused HTTP requests can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_REQUEST.
Additionally, as long as HTTP response headers were not sent downstream,
a HTTP response can be sent using proxy_send_local_response.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_REQUEST_TRAILERSfields downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) num_headersi32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called when HTTP response headers are received from upstream.
All num_headers headers can be retrieved and/or modified using
proxy_get_header_map_pairs and/or proxy_set_header_map_pairs
with map_id set to HTTP_RESPONSE_HEADERS.
Individual headers can be retrieved and/or modified using
proxy_get_header_map_value, proxy_replace_header_map_value,
proxy_add_header_map_value and/or proxy_remove_header_map_value
with map_id set to HTTP_RESPONSE_HEADERS.
Paused HTTP requests can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_RESPONSE.
Additionally, instead of forwarding the HTTP response from upstream,
a new HTTP response can be sent using proxy_send_local_response.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_RESPONSE_HEADERSfields downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) body_sizei32 (bool) end_of_stream
- returns:
i32 (proxy_action_t) action
Called for each chunk of HTTP response body received from upstream, even when the processing is paused.
Response body chunk (of body_size) can be retrieved and/or modified
using proxy_get_buffer_bytes and/or proxy_set_buffer_bytes
with buffer_id set to HTTP_RESPONSE_BODY.
body_size represents the total available size of the body that can be
retrieved, and its value will increment if the processing is paused and
the body is buffered by the host and not forwarded downstream.
Paused HTTP responses can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_RESPONSE.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_RESPONSE_BODYbuffer downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) stream_context_idi32 (size_t) num_trailers
- returns:
i32 (proxy_action_t) action
Called when HTTP response trailers are received from upstream.
All num_trailers trailers can be retrieved and/or modified using
proxy_get_header_map_pairs and/or proxy_set_header_map_pairs
with map_id set to HTTP_RESPONSE_TRAILERS.
Individual trailers can be retrieved and/or modified using
proxy_get_header_map_value, proxy_replace_header_map_value,
proxy_add_header_map_value and/or proxy_remove_header_map_value
with map_id set to HTTP_RESPONSE_TRAILERS.
Paused HTTP requests can be resumed using proxy_continue_stream
or closed using proxy_close_stream with stream_type set to
HTTP_REQUEST.
Plugin must return one of the following values:
CONTINUEto forwardHTTP_RESPONSE_TRAILERSfields downstream.PAUSEto pause processing.
- params:
i32 (uint32_t) status_codei32 (const char *) status_code_details_datai32 (size_t) status_code_details_sizei32 (const uint8_t *) body_datai32 (size_t) body_sizei32 (const uint8_t *) serialized_headers_datai32 (size_t) serialized_headers_sizei32 (uint32_t) grpc_status
- returns:
i32 (proxy_status_t) status
Sends HTTP response with body (body_data, body_size) and
serialized headers (serialized_headers_data,
serialized_headers_size).
This can be used as long as HTTP response headers were not sent downstream.
Returned status value is:
OKon success.INVALID_MEMORY_ACCESSwhenstatus_code_details_data,status_code_details_size,body_data,body_size,serialized_headers_dataand/orserialized_headers_sizepoint to invalid memory address.
- params:
i32 (const char *) upstream_name_datai32 (size_t) upstream_name_sizei32 (const uint8_t *) serialized_headers_datai32 (size_t) serialized_headers_sizei32 (const uint8_t *) body_datai32 (size_t) body_sizei32 (const uint8_t *) serialized_trailers_datai32 (size_t) serialized_trailers_sizei32 (uint32_t) timeouti32 (uint32_t *) return_call_id
- returns:
i32 (proxy_status_t) status
Sends HTTP request with serialized headers (serialized_headers_data,
serialized_headers_size), body, and serialized trailers
(serialized_trailers_data, serialized_trailers_size)
to upstream (upstream_name_data, upstream_name_size).
proxy_on_http_call_response will be called with return_call_id
when the response is received by the host, or after the timeout.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownupstream, or whenheadersare missing required:authority,:methodand/or:pathvalues.INTERNAL_FAILUREwhen the host failed to send the requested HTTP call.INVALID_MEMORY_ACCESSwhenupstream_data,upstream_size,serialized_headers_data,serialized_headers_sizebody_data,body_size,serialized_trailers_data,serialized_trailers_sizeand/orreturn_call_idpoint to invalid memory address.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) call_idi32 (size_t) num_headersi32 (size_t) body_sizei32 (size_t) num_trailers
- returns:
- none
Called when HTTP response for call_id sent using
proxy_http_call is received.
If num_headers is 0, then the HTTP call failed.
All num_headers headers can be retrieved using
proxy_get_header_map_pairs
or individually proxy_get_header_map_value
with map_id set to HTTP_CALL_RESPONSE_HEADERS.
Response body (of body_size) can be retrieved using
proxy_get_buffer_bytes with buffer_id set to
HTTP_RESPONSE_BODY.
All num_trailers trailers can be retrieved using
proxy_get_header_map_pairs
or individually proxy_get_header_map_value
with map_id set to HTTP_CALL_RESPONSE_TRAILERS.
- params:
i32 (const char *) upstream_name_datai32 (size_t) upstream_name_sizei32 (const char *) service_name_datai32 (size_t) service_name_sizei32 (const char *) method_name_datai32 (size_t) method_name_sizei32 (const uint8_t *) serialized_initial_metadata_datai32 (size_t) serialized_initial_metadata_sizei32 (const uint8_t *) message_datai32 (size_t) message_sizei32 (uint32_t) timeouti32 (uint32_t *) return_call_id
- returns:
i32 (proxy_status_t) status
Sends gRPC message (message_data, message_size) with serialized
initial metadata (serialized_initial_metadata_data,
serialized_initial_metadata_size)
to gRPC method (method_name_data, method_name_size)
on gRPC service (service_name_data, service_name_size)
on upstream (upstream_name_data, upstream_name_size).
proxy_on_grpc_receive or proxy_on_grpc_close will be called
with return_call_id when the response is received by the host, or
after the timeout.
return_call_id can also be used to cancel the outstanding request
using proxy_grpc_cancel or close it using proxy_grpc_close.
Returned status value is:
OKon success.PARSE_FAILUREfor unknownupstream.INTERNAL_FAILUREwhen the host failed to send a gRPC call.INVALID_MEMORY_ACCESSwhenupstream_data,upstream_size,service_name_data,service_name_sizemethod_name_data,method_name_size,serialized_initial_metadata_data,serialized_initial_metadata_size,message_data,message_sizeand/orreturn_call_idpoint to invalid memory address.
- params:
i32 (const char *) upstream_name_datai32 (size_t) upstream_name_sizei32 (const char *) service_name_datai32 (size_t) service_name_sizei32 (const char *) method_name_datai32 (size_t) method_name_sizei32 (const uint8_t *) serialized_initial_metadata_datai32 (size_t) serialized_initial_metadata_sizei32 (uint32_t *) return_stream_id
- returns:
i32 (proxy_status_t) status
Opens gRPC stream with serialized initial metadata
(serialized_initial_metadata_data, serialized_initial_metadata_size)
to gRPC method (method_name_data, method_name_size)
on gRPC service (service_name_data, service_name_size)
on upstream (upstream_name_data, upstream_name_size).
gRPC messages can be sent on this stream using proxy_grpc_send
with return_stream_id.
proxy_on_grpc_receive or proxy_on_grpc_close will be called
with return_stream_id when the response is received by the host,
or after the timeout.
return_stream_id can also be used to cancel outstanding gRPC messages
using proxy_grpc_cancel or close this gRPC stream using
proxy_grpc_close.
Returned status value is:
OKon success.PARSE_FAILUREfor unknownupstream.INTERNAL_FAILUREwhen the host failed to open gRPC stream.INVALID_MEMORY_ACCESSwhenupstream_data,upstream_size,service_name_data,service_name_sizemethod_name_data,method_name_size,serialized_initial_metadata_data,serialized_initial_metadata_sizeand/orreturn_stream_idpoint to invalid memory address.
- params:
i32 (uint32_t) stream_idi32 (const uint8_t *) message_datai32 (size_t) message_sizei32 (bool) end_stream
- returns:
i32 (proxy_status_t) status
Sends gRPC message (message_data, message_size) on the gRPC stream
stream_id previously established using proxy_grpc_stream.
Returned status value is:
OKon success.BAD_ARGUMENTfor invalidstream_id.NOT_FOUNDfor unknownstream_id.INVALID_MEMORY_ACCESSwhenmessage_dataand/ormessage_sizepoint to invalid memory address.
- params:
i32 (uint32_t) call_or_stream_id
- returns:
i32 (proxy_status_t) status
Cancels call_or_stream_id previously started using
proxy_grpc_call or proxy_grpc_stream.
Returned status value is:
OKon success.BAD_ARGUMENTfor invalidcall_or_stream_id.NOT_FOUNDfor unknowncall_or_stream_id.
- params:
i32 (uint32_t) call_or_stream_id
- returns:
i32 (proxy_status_t) status
Closes call_or_stream_id previously started using
proxy_grpc_call or proxy_grpc_stream.
Returned status value is:
OKon success.BAD_ARGUMENTfor invalidcall_or_stream_id.NOT_FOUNDfor unknowncall_or_stream_id.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) call_idi32 (size_t) num_elements
- returns:
- none
Called when initial gRPC metadata for call_id opened using
proxy_grpc_call or proxy_grpc_stream is received.
All num_elements elements can be retrieved using
proxy_get_header_map_pairs or individually
proxy_get_header_map_value with map_id set to
GRPC_CALL_INITIAL_METADATA.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) call_idi32 (size_t) message_size
- returns:
- none
Called when the response gRPC message for call_id sent using
proxy_grpc_call or proxy_grpc_send is received.
Message (of message_size) can be retrieved using
proxy_get_buffer_bytes with buffer_id set to GRPC_CALL_MESSAGE.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) call_idi32 (size_t) num_elements
- returns:
- none
Called when trailing gRPC metadata for call_id opened using
proxy_grpc_call or proxy_grpc_stream is received.
All num_elements elements can be retrieved using
proxy_get_header_map_pairs or individually
proxy_get_header_map_value with map_id set to
GRPC_CALL_TRAILING_METADATA.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) call_idi32 (uint32_t) status_code
- returns:
- none
Called when gRPC call or stream call_id opened using
proxy_grpc_call or proxy_grpc_stream is received.
gRPC status message can be retrieved using proxy_get_status.
- params:
i32 (const char *) key_datai32 (size_t) key_sizei32 (const uint8_t *) value_datai32 (size_t) value_sizei32 (uint32_t) cas
- returns:
i32 (proxy_status_t) status
Sets shared data identified by the key (key_data, key_value)
to the value (value_data, value_size).
If the compare-and-swap value (cas) is set to a non-zero value,
then it must match the host's compare-and-swap value in order for
the update to succeed.
Returned status value is:
OKon success.CAS_MISMATCHwhencasdoesn't match host's compare-and-swap value.INVALID_MEMORY_ACCESSwhenkey_data,key_size,value_data,value_sizeand/orcaspoint to invalid memory address.
- params:
i32 (const char *) key_datai32 (size_t) key_sizei32 (uint8_t **) return_value_datai32 (size_t *) return_value_sizei32 (uint32_t *) return_cas
- returns:
i32 (proxy_status_t) status
Returns shared value (return_value) identified by the key (key_data,
key_value).
The compare-and-swap value (return_cas) can be used for atomically
updating this value using proxy_set_shared_data.
Returned status value is:
OKon success.NOT_FOUNDwhen the requested key was not found.INVALID_MEMORY_ACCESSwhenkey_data,key_size,return_value_data,return_value_sizeand/orreturn_caspoint to invalid memory address.
- params:
i32 (const char *) name_datai32 (size_t) name_sizei32 (uint32_t *) return_queue_id
- returns:
i32 (proxy_status_t) status
Registers shared queue under a name (name_data, name_size).
If the named queue already exists, then it's going to be opened instead of creating a new empty queue.
Items can be enqueued/dequeued on the created/opened queue using
proxy_enqueue_shared_queue and/or proxy_dequeue_shared_queue
with return_queue_id.
Returned status value is:
OKon success.INVALID_MEMORY_ACCESSwhenname_data,name_sizeand/orreturn_queue_idpoint to invalid memory address.
- params:
i32 (const char *) vm_id_datai32 (size_t) vm_id_sizei32 (const char *) name_datai32 (size_t) name_sizei32 (uint32_t *) return_queue_id
- returns:
i32 (proxy_status_t) status
Resolves existing shared queue using the provided VM ID (vm_id_data,
vm_id_size) and name (name_data, name_size).
Items can be enqueued/dequeued on the opened queue using
proxy_enqueue_shared_queue and/or proxy_dequeue_shared_queue
with return_queue_id.
Returned status value is:
OKon success.NOT_FOUNDwhen the requested queue was not found.INVALID_MEMORY_ACCESSwhenvm_id_data,vm_id_size,name_data,name_sizeand/orreturn_queue_idpoint to invalid memory address.
- params:
i32 (uint32_t) queue_idi32 (const uint8_t *) value_datai32 (size_t) value_size
- returns:
i32 (proxy_status_t) status
Adds item (value_data, value_size) to the end of the queue
queue_id.
Returned status value is:
OKon success.NOT_FOUNDwhen the requestedqueue_idwas not found.INVALID_MEMORY_ACCESSwhenvalue_dataand/orvalue_sizepoint to invalid memory address.
- params:
i32 (uint32_t) queue_idi32 (uint8_t **) return_value_datai32 (size_t *) return_value_size
- returns:
i32 (proxy_status_t) status
Retrieves value (return_value_data, return_value_size) from
the front of the queue queue_id.
Returned status value is:
OKon success.NOT_FOUNDwhen the requestedqueue_idwas not found.EMPTYwhen there is nothing to dequeue from the requested queue.INVALID_MEMORY_ACCESSwhenreturn_value_dataand/orreturn_value_sizepoint to invalid memory address.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) queue_id
- returns:
- none
Called when a new item is enqueued on the queue queue_id.
- params:
i32 (proxy_metric_type_t) metric_typei32 (const char *) name_datai32 (size_t) name_sizei32 (uint32_t *) return_metric_id
- returns:
i32 (proxy_status_t) status
Defines a new metric of type metric_type with a name (name_data,
name_size).
Its value can be modified and/or retrieved using
proxy_record_metric, proxy_increment_metric
and/or proxy_get_metric with return_metric_id.
Returned status value is:
OKon success.BAD_ARGUMENTfor unknownmetric_type.INVALID_MEMORY_ACCESSwhenname_data,name_sizeand/orreturn_metric_idpoint to invalid memory address.
- params:
i32 (uint32_t) metric_idi64 (uint64_t) value
- returns:
i32 (proxy_status_t) status
Sets metric metric_id to the value.
Returned status value is:
OKon success.NOT_FOUNDwhen the requestedmetric_idwas not found.
- params:
i32 (uint32_t) metric_idi64 (int64_t) delta
- returns:
i32 (proxy_status_t) status
Changes metric metric_id by the delta.
Returned status value is:
OKon success.NOT_FOUNDwhen the requestedmetric_idwas not found.BAD_ARGUMENTwhen the requesteddeltacannot be applied tometric_id(e.g. trying to decrement counter).
- params:
i32 (uint32_t) metric_idi32 (uint64_t *) return_value
- returns:
i32 (proxy_status_t) status
Retrieves return_value of the metric metric_id.
Returned status value is:
OKon success.NOT_FOUNDwhen the requestedmetric_idwas not found.INVALID_MEMORY_ACCESSwhenreturn_valuepoints to invalid memory address.
Warning Properties are implementation-dependent and not stable across different versions of the same host.
- params:
i32 (const uint8_t *) path_datai32 (size_t) path_sizei32 (uint8_t **) return_value_datai32 (size_t *) return_value_size
- returns:
i32 (proxy_status_t) status
Retrieves value (return_value_data, return_value_size)
of the property (path_data, path_size).
path_data is a serialized list of path segments.
Returned status value is:
OKon success.NOT_FOUNDwhen there was no property found at the requestedpath.SERIALIZATION_FAILUREwhen host failed to serialize property.INVALID_MEMORY_ACCESSwhenpath_data,path_size,return_value_dataand/orreturn_value_sizepoint to invalid memory address.
- params:
i32 (const uint8_t *) path_datai32 (size_t) path_sizei32 (const uint8_t *) value_datai32 (size_t) value_size
- returns:
i32 (proxy_status_t) status
Sets value of the property (path_data, path_size) to the provided
value (value_data, value_size).
path_data is a serialized list of path segments.
Returned status value is:
OKon success.NOT_FOUNDwhen there was no property found at the requestedpath.INVALID_MEMORY_ACCESSwhenpath_data,path_size,value_dataand/orvalue_sizepoint to invalid memory address.
Warning Properties are implementation-dependent and not stable across different versions of the same host. When targeting a specific host implementation (discouraged), please refer to its official documentation for a complete list of supported properties.
plugin_name(string) - plugin nameplugin_root_id(string) - plugin root IDplugin_vm_id(string) - plugin VM ID
connection.id(uint) - connection IDsource.address(string) - remote addresssource.port(int) - remote portdestination.address(string) - local addressdestination.port(int) - local portconnection.tls_version(string) - TLS versionconnection.requested_server_name(string) - TLS SNIconnection.mtls(bool) - true if the TLS client certificate was validatedconnection.subject_local_certificate(string) - subject of the local certificateconnection.subject_peer_certificate(string) - subject of the peer certificateconnection.dns_san_local_certificate(string) - first DNS entry in the local certificateconnection.dns_san_peer_certificate(string) - first DNS entry in the the peer certificateconnection.uri_san_local_certificate(string) - first URI entry in the local certificateconnection.uri_san_peer_certificate(string) - first URI entry in the peer certificateconnection.sha256_peer_certificate_digest(string) - SHA256 digest of the peer certificate
upstream.address(string) - remote addressupstream.port(int) - remote portupstream.local_address(string) - local addressupstream.local_port(int) - local portupstream.tls_version(string) - TLS versionupstream.subject_local_certificate(string) - subject of the local certificateupstream.subject_peer_certificate(string) - subject of the peer certificateupstream.dns_san_local_certificate(string) - first DNS entry in the local certificateupstream.dns_san_peer_certificate(string) - first DNS entry in the peer certificateupstream.uri_san_local_certificate(string) - first URI entry in the local certificateupstream.uri_san_peer_certificate(string) - first URI entry in the peer certificateupstream.sha256_peer_certificate_digest(string) - SHA256 digest of the peer certificate
request.protocol(string) - HTTP version (HTTP/1.0,HTTP/1.1,HTTP/2,HTTP/3)request.time(timestamp) - time of the first byte receivedrequest.duration(duration) - total duration of the HTTP requestrequest.size(int) - size of the HTTP request bodyrequest.total_size(int) - total size of the HTTP request (including HTTP headers and trailers)
response.size(int) - size of the HTTP response bodyresponse.total_size(int) - total size of the HTTP response (including HTTP headers and trailers)
- params:
i32 (const char *) name_datai32 (size_t) name_sizei32 (const uint8_t *) arguments_datai32 (size_t) arguments_sizei32 (uint8_t **) return_results_datai32 (size_t *) return_results_size
- returns:
i32 (proxy_status_t) status
Calls registered foreign function (name_data, name_size)
with arguments (arguments_data, arguments_size).
Return value(s) (return_results_data, return_results_size)
are optional.
Returned status value is:
OKon success.NOT_FOUNDwhen the requested function was not found.INVALID_MEMORY_ACCESSwhenname_data,name_size,arguments_data,arguments_size,return_results_dataand/orreturn_results_sizepoint to invalid memory address.
- params:
i32 (uint32_t) plugin_context_idi32 (uint32_t) function_idi32 (size_t) arguments_size
- returns:
- none
Called when a registered foreign callback function_id is called.
Its arguments (of arguments_size) can be retrieved using
proxy_get_buffer_bytes with buffer_id set to
FOREIGN_FUNCTION_ARGUMENTS.
Various unimplemented WASI functions that are expected to be present
when the Wasm module is compiled for the wasm32-wasi target.
- params:
i32 (size_t *) return_argci32 (size_t *) return_argv_buffer_size
- returns:
i32 (wasi_errno_t) errno
Hosts must write 0 to both output arguments to prevent
wasi_snapshot_preview1.args_get from being called.
Returned errno value is:
SUCCESSon success.FAULTwhenreturn_argcand/orreturn_argv_buffer_sizepoint to invalid memory address.
- params:
i32 (uint8_t **) return_argvi32 (uint8_t *) return_argv_size
- returns:
i32 (wasi_errno_t) errno
This function should not be called if zero sizes were returned
in wasi_snapshot_preview1.args_sizes_get.
Returned errno value is:
SUCCESSon success.
- params:
i32 (uint32_t) exit_code
- returns:
- none
This function is never called.
Note The encoding of integers is little-endian.
Non-empty maps are serialized as:
- 32-bit integer containing the number of keys in the map,
- a series of pairs of 32-bit integers containing length of key and value,
- a series of pairs of byte sequences containing key and value, with each
key and value byte sequence terminated by a
NULL(0x00) character.
e.g. the map {{"a": "1"}, {"b": "22"}} would be serialized as:
0x02,0x01,0x01,0x01,0x02,0x61,0x00,0x49,0x00,0x62,0x00,0x50,0x50,0x00.
An empty map may be represented either as an empty value (size=0), or as
a single 0x00 byte (size=1).
Path data for the [proxy_get_property] and [property_set_property] hostcalls
consists of a sequence of path segments. The path segments are separated by
NULL (0x00) characters.
e.g. the path segments ["foo", "bar"] would be serialized as:
0x66,0x6f,0x6f,0x00,0x62,0x61,0x72
Host implementations should tolerate a NULL character at the end of the
combined path data string, if present.
Hosts should maintain a list of external resources (e.g. upstream hosts) that each plugin instance can communicate with.
Hosts should enforce limits on memory usage and maximum CPU time that plugins can consume during each invocation.
In case of a crashing WasmVM (e.g. because of a bug in Proxy-Wasm Plugin), the host should log the information about the crash, including stacktrace, and create a new instance of a WasmVM and the Proxy-Wasm Plugin.
The number of crashes should be tracked and rate-limited to prevent entering the crash-loop, when new instances keep crashing and creation of new WasmVMs is consuming too much resources leading to a denial of service (DoS).
Upon reaching the limit, the host should reject new connections and/or requests that rely on the broken plugin, returning errors to clients, unless the plugin is optional, in which case its execution may be skipped.
Plugins can change the effective context to a different connection/request.
Hosts should be aware of this, and might limit the ability to perform context changes to unrelated connections/requests.
TRACE=0DEBUG=1INFO=2WARN=3ERROR=4CRITICAL=5
OK=0NOT_FOUND=1BAD_ARGUMENT=2SERIALIZATION_FAILURE=3PARSE_FAILURE=4INVALID_MEMORY_ACCESS=6EMPTY=7CAS_MISMATCH=8INTERNAL_FAILURE=10UNIMPLEMENTED=12
CONTINUE=0PAUSE=1
HTTP_REQUEST_BODY=0HTTP_RESPONSE_BODY=1DOWNSTREAM_DATA=2UPSTREAM_DATA=3HTTP_CALL_RESPONSE_BODY=4GRPC_CALL_MESSAGE=5VM_CONFIGURATION=6PLUGIN_CONFIGURATION=7FOREIGN_FUNCTION_ARGUMENTS=8
HTTP_REQUEST_HEADERS=0HTTP_REQUEST_TRAILERS=1HTTP_RESPONSE_HEADERS=2HTTP_RESPONSE_TRAILERS=3GRPC_CALL_INITIAL_METADATA=4GRPC_CALL_TRAILING_METADATA=5HTTP_CALL_RESPONSE_HEADERS=6HTTP_CALL_RESPONSE_TRAILERS=7
UNKNOWN=0LOCAL=1REMOTE=2
HTTP_REQUEST=0HTTP_RESPONSE=1DOWNSTREAM=2UPSTREAM=3
COUNTER=0GAUGE=1HISTOGRAM=2
SUCCESS=0BADF=8FAULT=21INVAL=28NOTSUP=58
STDOUT=1STDERR=2
REALTIME=0MONOTONIC=1