@@ -59,8 +59,7 @@ these to create and return instances of its own subclasses of `RootContext` and
59
59
60
60
``` c++
61
61
static RegisterContextFactory register_ExampleContext (
62
- CONTEXT_FACTORY(ExampleContext), ROOT_FACTORY(ExampleRootContext),
63
- "my_root_id");
62
+ CONTEXT_FACTORY(ExampleContext), ROOT_FACTORY(ExampleRootContext));
64
63
```
65
64
66
65
`ROOT_FACTORY` and `CONTEXT_FACTORY` are convenience macros for lambdas that
@@ -113,24 +112,36 @@ in the lifecycle of a stream:
113
112
* `onCreate`: called when handling of a new stream starts.
114
113
* `onDone`: called when the host is done processing the stream.
115
114
* `onLog`: called after the host is done processing the stream, if the plugin is
116
- being used for access logging.
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)
117
+ extension).
117
118
* `onDelete`: called after the plugin has completed all processing related to
118
119
the stream, as indication to release resources.
119
120
120
- `Context` instances also receive callbacks corresponding to stream events:
121
+ `Context` instances also receive callbacks corresponding to stream events. For
122
+ HTTP or gRPC streams, these are:
121
123
122
124
* `onRequestHeaders`: called when HTTP or gRPC request headers are received.
123
125
* `onRequestBody`: called when HTTP or gRPC request body data is received.
124
126
* `onRequestTrailers`: called when HTTP or gRPC request trailers are received.
125
127
* `onResponseHeaders`: called when HTTP or gRPC response headers are received.
126
128
* `onResponseBody`: called when HTTP or gRPC response body data is received.
127
129
* `onResponseTrailers`: called when HTTP or gRPC response trailers are received.
130
+
131
+ For TCP streams, `Context` instances may receive the following callbacks:
132
+
128
133
* `onNewConnection`: called when a new connection is established.
129
134
* `onDownstreamData`: called when a new chunk of data is received from
130
135
downstream over a connection.
131
136
* `onUpstreamData`: called when a new chunk of data is received from upstream
132
137
over a connection.
133
138
139
+ Callback methods return status enums that indicate whether and how the host
140
+ should continue to process the stream. Status enum meanings are specified in the
141
+ doc comments in [proxy_wasm_enums.h]. Callbacks can also generate an immediate
142
+ local response to an HTTP or gRPC request using the `sendLocalResponse`
143
+ hostcall.
144
+
134
145
For API details, see doc comments for the `Context` class in [proxy_wasm_api.h].
135
146
136
147
## Buffers
@@ -217,7 +228,7 @@ inspect data sent by the upstream client could override the
217
228
`Context::onUpstreamData` method.
218
229
219
230
To access the actual data being proxied, plugin code would use the
220
- buffer-related hostcalls described in [Buffers], specifying
231
+ buffer-related hostcalls described in [Buffers](#Buffers) , specifying
221
232
`NetworkUpstreamData` as the `WasmBufferType`.
222
233
223
234
## Timers
@@ -326,18 +337,8 @@ prepended to the log message:
326
337
* `LOG_ERROR`
327
338
* `LOG_CRITICAL`
328
339
329
- Additionally, there is a LOG macro that accepts log level as a
330
- parameter. These macros layer on top of hostcall functions:
331
-
332
- * `logTrace`
333
- * `logDebug`
334
- * `logInfo`
335
- * `logWarn`
336
- * `logError`
337
- * `logCritical`
338
-
339
- All macros and hostcalls above allow plugin execution to continue. There
340
- is one further logging hostcall that terminates plugin execution:
340
+ The macros above allow plugin execution to continue. There is also a logging
341
+ hostcall that terminates plugin execution:
341
342
342
343
* `logAbort`: logs at Critical level, then aborts the plugin
343
344
0 commit comments