2
2
3
3
This page explains the main concepts and structure of the C++ SDK API. For
4
4
detailed API semantics, refer to the doc comments in the header files listed in
5
- the [ codemap ] ( #codemap ) section, in particular [ proxy_wasm_api.h] .
5
+ the [ Codemap ] section, in particular [ proxy_wasm_api.h] .
6
6
7
7
## Concepts and terminology
8
8
@@ -33,12 +33,13 @@ the [codemap](#codemap) section, in particular [proxy_wasm_api.h].
33
33
with the current stream. The hostcalls are defined as methods on ` Context `
34
34
base classes, which plugin code can call.
35
35
36
- There are two types of Contexts: * Root Contexts* and * Stream Contexts*
37
- (sometimes just called Contexts). Root Contexts are represented by the
38
- ` RootContext ` class, and are associated with plugins as a whole--i.e. within a
39
- given Wasm VM, there is one Root Context per plugin. Stream Contexts are
40
- represented by the ` Context ` class, and are associated with individual
41
- streams--i.e. incoming HTTP/gRPC calls, or TCP streams.
36
+ There are two types of Contexts: * Plugin Contexts* (also known as Root
37
+ Contexts) and * Stream Contexts* (sometimes just called Contexts). Plugin
38
+ Contexts are represented by the ` RootContext ` class, and are associated with
39
+ plugins as a whole--i.e. within a given Wasm VM, there is one Plugin Context
40
+ per plugin. Stream Contexts are represented by the ` Context ` class, and are
41
+ associated with individual streams--i.e. incoming HTTP/gRPC calls, or TCP
42
+ streams.
42
43
43
44
In the C++ SDK programming model, plugins are implemented by subclassing
44
45
` RootContext ` and/or ` Context ` , and providing implementations of their various
@@ -53,7 +54,7 @@ the [codemap](#codemap) section, in particular [proxy_wasm_api.h].
53
54
` RegisterContextFactory ` is the mechanism for bootstrapping plugin code. Plugin
54
55
code instantiates a ` RegisterContextFactory ` in a static
55
56
variable. ` RegisterContextFactory ` takes as constructor params ` std::function ` s
56
- for creating new root context and stream context instances. The plugin can use
57
+ for creating new plugin context and stream context instances. The plugin can use
57
58
these to create and return instances of its own subclasses of ` RootContext ` and
58
59
` Context ` . For example:
59
60
@@ -112,8 +113,7 @@ in the lifecycle of a stream:
112
113
* `onCreate`: called when handling of a new stream starts.
113
114
* `onDone`: called when the host is done processing the stream.
114
115
* `onLog`: called after the host is done processing the stream, if the plugin is
115
- being used for access logging (for example, in Envoy, as a
116
- [WasmAccessLog](https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/access_loggers/wasm/v3/wasm.proto#extensions-access-loggers-wasm-v3-wasmaccesslog)
116
+ being used for access logging (for example, in Envoy, as a [WasmAccessLog]
117
117
extension).
118
118
* `onDelete`: called after the plugin has completed all processing related to
119
119
the stream, as indication to release resources.
@@ -122,10 +122,12 @@ in the lifecycle of a stream:
122
122
HTTP or gRPC streams, these are:
123
123
124
124
* `onRequestHeaders`: called when HTTP or gRPC request headers are received.
125
- * `onRequestBody`: called when HTTP or gRPC request body data is received.
125
+ * `onRequestBody`: called when a new chunk of HTTP or gRPC request body data is
126
+ received.
126
127
* `onRequestTrailers`: called when HTTP or gRPC request trailers are received.
127
128
* `onResponseHeaders`: called when HTTP or gRPC response headers are received.
128
- * `onResponseBody`: called when HTTP or gRPC response body data is received.
129
+ * `onResponseBody`: called when a new chunk of HTTP or gRPC response body data
130
+ is received.
129
131
* `onResponseTrailers`: called when HTTP or gRPC response trailers are received.
130
132
131
133
For TCP streams, `Context` instances may receive the following callbacks:
@@ -169,7 +171,7 @@ individual callbacks in [proxy_wasm_api.h] for which buffers are accessible in
169
171
each callback. Documentation for the `WasmData` class is also in
170
172
[proxy_wasm_api.h].
171
173
172
- ## Handling HTTP and gRPC requests
174
+ ## Handling HTTP and gRPC request headers and trailers
173
175
174
176
Plugins that handle HTTP and gRPC requests do so by overriding one or more of
175
177
the HTTP-related callback methods declared by the `Context` class (see the
@@ -207,14 +209,13 @@ headers, and response trailers.
207
209
gRPC requests received by the proxy are dispatched to the plugin using the same
208
210
`Context` callback methods as HTTP requests. Plugin code can determine whether
209
211
an incoming request is gRPC in the same way that network proxies do: by checking
210
- if the ":method" pseudoheader has value "POST" and the "content-type" header has
211
- value "application/grpc".
212
+ if the ":method" pseudoheader has value "POST" and the "content-type" header
213
+ starts with value "application/grpc".
212
214
213
215
Plugin callbacks can access the request URL via the ":method", ":scheme",
214
216
":authority", and ":path" pseudo-headers defined in [RFC 9113 section
215
- 8.3.1](https://datatracker.ietf.org/doc/html/rfc9113#section-8.3.1). They can
216
- access HTTP response status via the ":status" pseudo-header defined in [RFC 9113
217
- section 8.3.2](https://datatracker.ietf.org/doc/html/rfc9113#section-8.3.2).
217
+ 8.3.1]. They can access HTTP response status via the ":status" pseudo-header
218
+ defined in [RFC 9113 section 8.3.2].
218
219
219
220
For API details, see doc comments accompanying the functions in
220
221
[proxy_wasm_api.h].
@@ -228,7 +229,7 @@ inspect data sent by the upstream client could override the
228
229
`Context::onUpstreamData` method.
229
230
230
231
To access the actual data being proxied, plugin code would use the
231
- buffer-related hostcalls described in [Buffers](#Buffers) , specifying
232
+ buffer-related hostcalls described in [Buffers], specifying
232
233
`NetworkUpstreamData` as the `WasmBufferType`.
233
234
234
235
## Timers
@@ -371,7 +372,7 @@ for representing and updating metrics:
371
372
- `Metric`: all of the above
372
373
373
374
Metrics can be subdivided by tags, using similar structure to [Envoy
374
- statistics](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/observability/statistics) .
375
+ statistics].
375
376
376
377
## Foreign function interface (FFI)
377
378
@@ -449,24 +450,35 @@ listed below:
449
450
450
451
* [ proxy_wasm_api.h] : main SDK API definition and implementation
451
452
* [ proxy_wasm_externs.h] : declarations for ABI-level hostcalls and callbacks
452
- * [ proxy_wasm_common.h] ( ../proxy_wasm_common.h ) : supporting types for the API
453
- * [ proxy_wasm_enums.h] ( ../proxy_wasm_enums.h ) : supporting enums for the API
454
- * [ proxy_wasm_intrinsics.js] ( ../proxy_wasm_intrinsics.js ) : list of Proxy-Wasm
455
- ABI hostcalls, for use by [ Emscripten] ( https://emscripten.org )
456
- * [ proxy_wasm_intrinsics.proto] ( ../proxy_wasm_intrinsics.proto ) : protobuf types
457
- needed for gRPC calls
458
- * [ proxy_wasm_intrinsics.h ] ( ../proxy_wasm_intrinsics.h ) : combined header file
459
- that includes all other header files
460
- * [ proxy_wasm_intrinsics.cc ] ( ../proxy_wasm_intrinsics.cc ) : implementation of
461
- dispatch from ABI-level Proxy-Wasm callbacks to [ Context ] and [ RootContext ]
462
- callback methods.
463
-
453
+ * [ proxy_wasm_common.h] : supporting types for the API
454
+ * [ proxy_wasm_enums.h] : supporting enums for the API
455
+ * [ proxy_wasm_intrinsics.js] : list of Proxy-Wasm ABI hostcalls, for use by
456
+ [ Emscripten]
457
+ * [ proxy_wasm_intrinsics.proto] : protobuf types needed for gRPC calls
458
+ * [ proxy_wasm_intrinsics.h ] : combined header file that includes all other header
459
+ files
460
+ * [ proxy_wasm_intrinsics.cc ] : implementation of dispatch from ABI-level
461
+ Proxy-Wasm callbacks to [ Context ] and [ RootContext ] callback methods.
462
+
463
+ [ Buffers ] : #buffers
464
+ [ Codemap ] : #codemap
464
465
[ Context ] : #context
466
+ [ Emscripten ] : https://emscripten.org
467
+ [ Envoy statistics ] : https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/observability/statistics
468
+ [ HTTP callouts ] : #http-callouts
469
+ [ RFC 9113 section 8.3.1 ] : https://datatracker.ietf.org/doc/html/rfc9113#section-8.3.1
470
+ [ RFC 9113 section 8.3.2 ] : https://datatracker.ietf.org/doc/html/rfc9113#section-8.3.2
465
471
[ RootContext ] : #rootcontext
466
- [ Timers ] : #timers
467
472
[ Shared queues ] : #shared-queues
468
- [ HTTP callouts ] : #http-callouts
473
+ [ Timers ] : #timers
474
+ [ WasmAccessLog ] : https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/access_loggers/wasm/v3/wasm.proto#extensions-access-loggers-wasm-v3-wasmaccesslog
469
475
[ gRPC callouts ] : #grpc-callouts
476
+ [ http_wasm_example.cc ] : ../example/http_wasm_example.cc
470
477
[ proxy_wasm_api.h ] : ../proxy_wasm_api.h
478
+ [ proxy_wasm_common.h ] : ../proxy_wasm_common.h
479
+ [ proxy_wasm_enums.h ] : ../proxy_wasm_enums.h
471
480
[ proxy_wasm_externs.h ] : ../proxy_wasm_externs.h
472
- [ http_wasm_example.cc ] : ../example/http_wasm_example.cc
481
+ [ proxy_wasm_intrinsics.cc ] : ../proxy_wasm_intrinsics.cc
482
+ [ proxy_wasm_intrinsics.h ] : ../proxy_wasm_intrinsics.h
483
+ [ proxy_wasm_intrinsics.js ] : ../proxy_wasm_intrinsics.js
484
+ [ proxy_wasm_intrinsics.proto ] : ../proxy_wasm_intrinsics.proto
0 commit comments