Skip to content

Commit 33acaf0

Browse files
committed
Address review comments for api_overview.md
Signed-off-by: Michael Warres <[email protected]>
1 parent 9152b60 commit 33acaf0

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

docs/api_overview.md

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This page explains the main concepts and structure of the C++ SDK API. For
44
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].
66

77
## Concepts and terminology
88

@@ -33,12 +33,13 @@ the [codemap](#codemap) section, in particular [proxy_wasm_api.h].
3333
with the current stream. The hostcalls are defined as methods on `Context`
3434
base classes, which plugin code can call.
3535

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.
4243

4344
In the C++ SDK programming model, plugins are implemented by subclassing
4445
`RootContext` and/or `Context`, and providing implementations of their various
@@ -53,7 +54,7 @@ the [codemap](#codemap) section, in particular [proxy_wasm_api.h].
5354
`RegisterContextFactory` is the mechanism for bootstrapping plugin code. Plugin
5455
code instantiates a `RegisterContextFactory` in a static
5556
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
5758
these to create and return instances of its own subclasses of `RootContext` and
5859
`Context`. For example:
5960

@@ -112,8 +113,7 @@ in the lifecycle of a stream:
112113
* `onCreate`: called when handling of a new stream starts.
113114
* `onDone`: called when the host is done processing the stream.
114115
* `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]
117117
extension).
118118
* `onDelete`: called after the plugin has completed all processing related to
119119
the stream, as indication to release resources.
@@ -122,10 +122,12 @@ in the lifecycle of a stream:
122122
HTTP or gRPC streams, these are:
123123
124124
* `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.
126127
* `onRequestTrailers`: called when HTTP or gRPC request trailers are received.
127128
* `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.
129131
* `onResponseTrailers`: called when HTTP or gRPC response trailers are received.
130132
131133
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
169171
each callback. Documentation for the `WasmData` class is also in
170172
[proxy_wasm_api.h].
171173
172-
## Handling HTTP and gRPC requests
174+
## Handling HTTP and gRPC request headers and trailers
173175
174176
Plugins that handle HTTP and gRPC requests do so by overriding one or more of
175177
the HTTP-related callback methods declared by the `Context` class (see the
@@ -207,14 +209,13 @@ headers, and response trailers.
207209
gRPC requests received by the proxy are dispatched to the plugin using the same
208210
`Context` callback methods as HTTP requests. Plugin code can determine whether
209211
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".
212214
213215
Plugin callbacks can access the request URL via the ":method", ":scheme",
214216
":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].
218219
219220
For API details, see doc comments accompanying the functions in
220221
[proxy_wasm_api.h].
@@ -228,7 +229,7 @@ inspect data sent by the upstream client could override the
228229
`Context::onUpstreamData` method.
229230
230231
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
232233
`NetworkUpstreamData` as the `WasmBufferType`.
233234
234235
## Timers
@@ -371,7 +372,7 @@ for representing and updating metrics:
371372
- `Metric`: all of the above
372373
373374
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].
375376
376377
## Foreign function interface (FFI)
377378
@@ -449,24 +450,35 @@ listed below:
449450

450451
* [proxy_wasm_api.h]: main SDK API definition and implementation
451452
* [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
464465
[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
465471
[RootContext]: #rootcontext
466-
[Timers]: #timers
467472
[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
469475
[gRPC callouts]: #grpc-callouts
476+
[http_wasm_example.cc]: ../example/http_wasm_example.cc
470477
[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
471480
[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

Comments
 (0)