Skip to content

Commit a912170

Browse files
committed
refactor(middleware): give HTTP hook RPCs package-unique names
Mirror bc90d94 from #4359: rename HttpHooks.EvaluateRequest and EvaluateResponse to EvaluateHttpRequestHook and EvaluateHttpResponseHook, and document in supervisor_middleware.proto that RPC names must be unique across the package's services. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 0c69f86 commit a912170

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎docs/extensibility/supervisor-middleware/operations.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ A middleware service handles one or more operations, such as HTTP requests or We
1414

1515
| Operation | Phase | When OpenShell calls your service | RPC |
1616
| --- | --- | --- | --- |
17-
| `HTTP_REQUEST` | `PRE_CREDENTIALS` | After network policy allows a request, before OpenShell injects provider credentials. | `HttpHooks.EvaluateRequest`, or legacy `EvaluateHttpRequest` |
18-
| `HTTP_RESPONSE` | `PRE_RETURN` | After the external service responds, before the sandbox receives the response. | `HttpHooks.EvaluateResponse`, or legacy `HttpResponsePreReturn.Evaluate` |
17+
| `HTTP_REQUEST` | `PRE_CREDENTIALS` | After network policy allows a request, before OpenShell injects provider credentials. | `HttpHooks.EvaluateHttpRequestHook`, or legacy `EvaluateHttpRequest` |
18+
| `HTTP_RESPONSE` | `PRE_RETURN` | After the external service responds, before the sandbox receives the response. | `HttpHooks.EvaluateHttpResponseHook`, or legacy `HttpResponsePreReturn.Evaluate` |
1919
| `WEBSOCKET_MESSAGE` | `PRE_CREDENTIALS` | When the sandbox opens a WebSocket connection, and for each text message it sends. | `EvaluateWebSocketSession` |
2020

2121
Your service declares each operation it supports as a binding, an operation and its phase, in its `Describe` manifest. OpenShell calls your service only for the operations it declares.
@@ -42,7 +42,7 @@ OpenShell never forwards free-form text from your service to the sandbox or to l
4242

4343
## HTTP
4444

45-
HTTP middleware inspects requests before OpenShell injects provider credentials and responses before the sandbox receives them. Implement `HttpHooks.EvaluateRequest` for `HTTP_REQUEST`, `HttpHooks.EvaluateResponse` for `HTTP_RESPONSE`, or both.
45+
HTTP middleware inspects requests before OpenShell injects provider credentials and responses before the sandbox receives them. Implement `HttpHooks.EvaluateHttpRequestHook` for `HTTP_REQUEST`, `HttpHooks.EvaluateHttpResponseHook` for `HTTP_RESPONSE`, or both.
4646

4747
Serve `HttpHooks` on the same endpoint as `SupervisorMiddleware`, which handles discovery and configuration. Each RPC invocation serves one binding phase, identified by `phase` in its preflight. Requests currently use `PRE_CREDENTIALS`; responses use `PRE_RETURN`.
4848

‎proto/supervisor_middleware.proto‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import "google/protobuf/struct.proto";
99
import "google/protobuf/duration.proto";
1010
import "extension.proto";
1111

12+
// Service and RPC naming.
13+
//
14+
// A middleware implements SupervisorMiddleware and the hook services for the
15+
// traffic it wants to inspect, all on one endpoint. Generated servers in some
16+
// languages, such as Python and Go, name each handler method after the RPC
17+
// alone, so one object that implements several of these services can have
18+
// only one handler per RPC name. Every RPC name must therefore be unique across
19+
// all services in this package, including deprecated ones.
20+
//
21+
// To add hooks for another protocol, add a <Protocol>Hooks service. Name each
22+
// RPC Evaluate<Protocol><Unit>Hook, after the unit it evaluates, and its
23+
// messages <Protocol><Unit>HookEvent and <Protocol><Unit>HookResult. For
24+
// example: HttpHooks.EvaluateHttpRequestHook(stream HttpRequestHookEvent)
25+
// returns (stream HttpRequestHookResult).
26+
1227
// SupervisorMiddleware discovers and configures one operator-run middleware.
1328
// It evaluates legacy HTTP requests and WebSocket messages.
1429
// Hook-specific services share the same registration and endpoint.
@@ -20,7 +35,7 @@ service SupervisorMiddleware {
2035
rpc ValidateConfig(ValidateConfigRequest) returns (ValidateConfigResponse);
2136

2237
// Deprecated: legacy HTTP hooks, removed in 0.2.0. Use
23-
// HttpHooks.EvaluateRequest.
38+
// HttpHooks.EvaluateHttpRequestHook.
2439
// EvaluateHttpRequest returns an allow, deny, or mutation decision for one
2540
// buffered HTTP request. OpenShell calls it for the HTTP_REQUEST bindings of
2641
// a service that does not require the HTTP hooks capability.
@@ -49,14 +64,14 @@ service HttpHooks {
4964
// extension.required_capabilities. Peers that predate HTTP hooks
5065
// reject such a service at Describe. One stream per request and middleware
5166
// stage. The first event is a request preflight.
52-
rpc EvaluateRequest(stream HttpRequestHookEvent)
67+
rpc EvaluateHttpRequestHook(stream HttpRequestHookEvent)
5368
returns (stream HttpRequestHookResult);
5469

5570
// HTTP hooks for responses, for the HTTP_RESPONSE bindings of a
5671
// service that requires the HTTP hooks capability. One stream per
5772
// response and middleware stage. The first event is a preflight of the
5873
// response head.
59-
rpc EvaluateResponse(stream HttpResponseHookEvent)
74+
rpc EvaluateHttpResponseHook(stream HttpResponseHookEvent)
6075
returns (stream HttpResponseHookResult);
6176
}
6277

@@ -67,7 +82,7 @@ message MiddlewareDescribeRequest {
6782
}
6883

6984
// Deprecated: legacy HTTP hooks, removed in 0.2.0. Use
70-
// HttpHooks.EvaluateResponse.
85+
// HttpHooks.EvaluateHttpResponseHook.
7186
// HttpResponsePreReturn evaluates one response for one middleware stage before
7287
// OpenShell returns it to the sandbox. OpenShell calls it for the HTTP_RESPONSE
7388
// bindings of a service that does not require the HTTP hooks
@@ -146,7 +161,7 @@ message ValidateConfigResponse {
146161
string reason = 2;
147162
}
148163

149-
// HTTP hooks. One ordered event in a HttpHooks.EvaluateRequest
164+
// HTTP hooks. One ordered event in a HttpHooks.EvaluateHttpRequestHook
150165
// stream. Preflight is always first and sees the preceding stage's completed
151166
// output headers. An inspect result is followed by begin
152167
// and exactly one body lifecycle: whole_body for WHOLE_BODY, or input_chunk
@@ -163,7 +178,7 @@ message HttpRequestHookEvent {
163178
}
164179
}
165180

166-
// HTTP hooks. One ordered event in a HttpHooks.EvaluateResponse
181+
// HTTP hooks. One ordered event in a HttpHooks.EvaluateHttpResponseHook
167182
// stream, in the order HttpRequestHookEvent describes.
168183
message HttpResponseHookEvent {
169184
oneof event {
@@ -176,7 +191,7 @@ message HttpResponseHookEvent {
176191
}
177192
}
178193

179-
// HTTP hooks. One ordered result in a HttpHooks.EvaluateRequest
194+
// HTTP hooks. One ordered result in a HttpHooks.EvaluateHttpRequestHook
180195
// stream. Preflight requires preflight_result or deny. WHOLE_BODY ends with
181196
// whole_body_result or deny. DUPLEX sends output_start before any
182197
// output_chunk, even for an empty output, and ends with finish or deny. An
@@ -196,7 +211,7 @@ message HttpRequestHookResult {
196211
}
197212
}
198213

199-
// HTTP hooks. One ordered result in a HttpHooks.EvaluateResponse
214+
// HTTP hooks. One ordered result in a HttpHooks.EvaluateHttpResponseHook
200215
// stream, under the rules HttpRequestHookResult describes, with
201216
// block_delivery instead of deny. Blocking delivery does not undo the
202217
// request already handled by the external service.
@@ -911,13 +926,13 @@ message MiddlewareExchangeProtocolError {}
911926
enum SupervisorMiddlewareOperation {
912927
SUPERVISOR_MIDDLEWARE_OPERATION_UNSPECIFIED = 0;
913928
// An HTTP request at PRE_CREDENTIALS. OpenShell calls
914-
// HttpHooks.EvaluateRequest when the service requires the
929+
// HttpHooks.EvaluateHttpRequestHook when the service requires the
915930
// openshell.supervisor-middleware.http-hooks capability, and the
916931
// deprecated EvaluateHttpRequest otherwise.
917932
SUPERVISOR_MIDDLEWARE_OPERATION_HTTP_REQUEST = 1;
918933
SUPERVISOR_MIDDLEWARE_OPERATION_WEBSOCKET_MESSAGE = 2;
919934
// A final HTTP response at PRE_RETURN. OpenShell calls
920-
// HttpHooks.EvaluateResponse when the service requires the HTTP
935+
// HttpHooks.EvaluateHttpResponseHook when the service requires the HTTP
921936
// hooks capability, and the deprecated HttpResponsePreReturn.Evaluate
922937
// otherwise.
923938
SUPERVISOR_MIDDLEWARE_OPERATION_HTTP_RESPONSE = 3;

‎rfc/0009-supervisor-middleware/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ links:
1919
|------|------------|--------|
2020
| 2026-07-17 | [#2010](https://github.com/NVIDIA/OpenShell/issues/2010) | Added unary HTTP request middleware with built-in and operator-run services. |
2121
| 2026-07-28 | [#2428](https://github.com/NVIDIA/OpenShell/issues/2428) | Added WebSocket preflight and text-message evaluation, and aligned the middleware API names, limits, and diagnostics. |
22-
| 2026-10-08 | [#2431](https://github.com/NVIDIA/OpenShell/issues/2431), [#3307](https://github.com/NVIDIA/OpenShell/issues/3307) | Added HTTP hooks (`HttpHooks.EvaluateRequest` and `HttpHooks.EvaluateResponse`), selected by a required extension capability, with buffered and streamed bodies, and deprecated legacy HTTP hooks. |
22+
| 2026-10-08 | [#2431](https://github.com/NVIDIA/OpenShell/issues/2431), [#3307](https://github.com/NVIDIA/OpenShell/issues/3307) | Added HTTP hooks (`HttpHooks.EvaluateHttpRequestHook` and `HttpHooks.EvaluateHttpResponseHook`), selected by a required extension capability, with buffered and streamed bodies, and deprecated legacy HTTP hooks. |
2323

2424
## Summary
2525

@@ -305,7 +305,7 @@ The `originating_process` is the same identity OpenShell resolves on the egress
305305
306306
#### HTTP hooks
307307

308-
- **RPCs.** `HttpHooks.EvaluateRequest` and `HttpHooks.EvaluateResponse` are bidirectional streams, each with its own event and result messages. One stream serves one stage for one HTTP message.
308+
- **RPCs.** `HttpHooks.EvaluateHttpRequestHook` and `HttpHooks.EvaluateHttpResponseHook` are bidirectional streams, each with its own event and result messages. One stream serves one stage for one HTTP message.
309309
- **Lifecycle.** Each stream starts with a preflight. The stage then continues without the body, rejects, or inspects the body as one `WHOLE_BODY` message or as a `DUPLEX` stream. HTTP preflights handle HTTP messages only, so connections OpenShell cannot inspect follow the chain-level rule above.
310310
- **Limits.** A `DUPLEX` stream has no total time or size limit, unless the route buffers request output before upstream contact. Then the preflight reports the route's own buffering limit as `max_output_body_bytes`, such as 10 MiB for SigV4 body signing.
311311
- **Failure behavior.** HTTP hooks always fail closed. The gateway rejects `on_error: fail_open` for them.

0 commit comments

Comments
 (0)