Skip to content

Commit 35163bb

Browse files
authored
Add support for closing of connections in the ABI/SDK. (#29)
* Add support for closing of connections in the ABI/SDK. Signed-off-by: John Plevyak <[email protected]>
1 parent 246314d commit 35163bb

File tree

6 files changed

+64
-53
lines changed

6 files changed

+64
-53
lines changed

proxy_wasm_api.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ class Context : public ContextBase {
436436
virtual FilterStatus onNewConnection() { return FilterStatus::Continue; }
437437
virtual FilterStatus onDownstreamData(size_t, bool) { return FilterStatus::Continue; }
438438
virtual FilterStatus onUpstreamData(size_t, bool) { return FilterStatus::Continue; }
439-
virtual void onDownstreamConnectionClose(PeerType) {}
440-
virtual void onUpstreamConnectionClose(PeerType) {}
439+
virtual void onDownstreamConnectionClose(CloseType) {}
440+
virtual void onUpstreamConnectionClose(CloseType) {}
441441

442442
virtual FilterHeadersStatus onRequestHeaders(uint32_t, bool) {
443443
return FilterHeadersStatus::Continue;
@@ -591,8 +591,12 @@ inline WasmResult setFilterStateStringValue(StringView key, StringView s) {
591591
}
592592

593593
// Continue/Respond/Route
594-
inline WasmResult continueRequest() { return proxy_continue_request(); }
595-
inline WasmResult continueResponse() { return proxy_continue_response(); }
594+
inline WasmResult continueRequest() { return proxy_continue_stream(WasmStreamType::Request); }
595+
inline WasmResult continueResponse() { return proxy_continue_stream(WasmStreamType::Response); }
596+
597+
inline WasmResult closeRequest() { return proxy_close_stream(WasmStreamType::Request); }
598+
inline WasmResult closeResponse() { return proxy_close_stream(WasmStreamType::Response); }
599+
596600
inline WasmResult sendLocalResponse(uint32_t response_code, StringView response_code_details,
597601
StringView body,
598602
const HeaderStringPairs &additional_response_headers,

proxy_wasm_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ enum class WasmBufferFlags : int32_t {
101101
// These must be powers of 2.
102102
EndOfStream = 1,
103103
};
104+
enum class WasmStreamType : int32_t {
105+
Request = 0,
106+
Response = 1,
107+
Downstream = 2,
108+
Upstream = 3,
109+
MAX = 3,
110+
};

proxy_wasm_enums.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ enum class MetricType : int32_t {
6565
Histogram = 2,
6666
Max = 2,
6767
};
68-
enum class PeerType : int32_t {
68+
enum class CloseType : int32_t {
6969
Unknown = 0,
70-
Local = 1,
71-
Remote = 2,
70+
Local = 1, // Close initiated by the proxy.
71+
Remote = 2, // Close initiated by the peer.
7272
};

proxy_wasm_externs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ extern "C" WasmResult proxy_get_property(const char *path_ptr, size_t path_size,
5050
extern "C" WasmResult proxy_set_property(const char *path_ptr, size_t path_size,
5151
const char *value_ptr, size_t value_size);
5252

53-
// Continue/Reply/Route
54-
extern "C" WasmResult proxy_continue_request();
55-
extern "C" WasmResult proxy_continue_response();
53+
// Continue/Close/Reply/Route
54+
extern "C" WasmResult proxy_continue_stream(WasmStreamType stream_type);
55+
extern "C" WasmResult proxy_close_stream(WasmStreamType stream_type);
5656
extern "C" WasmResult
5757
proxy_send_local_response(uint32_t response_code, const char *response_code_details_ptr,
5858
size_t response_code_details_size, const char *body_ptr, size_t body_size,

proxy_wasm_intrinsics.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ extern "C" PROXY_WASM_KEEPALIVE FilterStatus proxy_on_upstream_data(uint32_t con
169169
}
170170

171171
extern "C" PROXY_WASM_KEEPALIVE void proxy_on_downstream_connection_close(uint32_t context_id,
172-
uint32_t peer_type) {
173-
return getContext(context_id)->onDownstreamConnectionClose(static_cast<PeerType>(peer_type));
172+
uint32_t close_type) {
173+
return getContext(context_id)->onDownstreamConnectionClose(static_cast<CloseType>(close_type));
174174
}
175175

176176
extern "C" PROXY_WASM_KEEPALIVE void proxy_on_upstream_connection_close(uint32_t context_id,
177-
uint32_t peer_type) {
178-
return getContext(context_id)->onUpstreamConnectionClose(static_cast<PeerType>(peer_type));
177+
uint32_t close_type) {
178+
return getContext(context_id)->onUpstreamConnectionClose(static_cast<CloseType>(close_type));
179179
}
180180

181181
extern "C" PROXY_WASM_KEEPALIVE FilterHeadersStatus

proxy_wasm_intrinsics.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,43 @@
1616
*/
1717

1818
mergeInto(LibraryManager.library, {
19-
proxy_get_configuration: function () {},
20-
proxy_log: function () {},
21-
proxy_set_tick_period_milliseconds: function () {},
22-
proxy_get_current_time_nanoseconds: function() {},
23-
proxy_get_status: function () {},
24-
proxy_get_property: function () {},
25-
proxy_set_property: function () {},
26-
proxy_continue_request: function () {},
27-
proxy_continue_response: function () {},
28-
proxy_clear_route_cache: function () {},
29-
proxy_add_header_map_value: function () {},
30-
proxy_get_header_map_value: function () {},
31-
proxy_get_header_map_pairs: function () {},
32-
proxy_get_header_map_size: function () {},
33-
proxy_get_shared_data: function () {},
34-
proxy_set_shared_data: function () {},
35-
proxy_register_shared_queue: function () {},
36-
proxy_resolve_shared_queue: function () {},
37-
proxy_enqueue_shared_queue: function () {},
38-
proxy_dequeue_shared_queue: function () {},
39-
proxy_replace_header_map_value: function () {},
40-
proxy_remove_header_map_value: function () {},
41-
proxy_get_buffer_bytes: function () {},
42-
proxy_get_buffer_status: function () {},
43-
proxy_set_buffer_bytes: function () {},
44-
proxy_http_call: function () {},
45-
proxy_define_metric: function () {},
46-
proxy_increment_metric: function () {},
47-
proxy_record_metric: function () {},
48-
proxy_get_metric: function () {},
49-
proxy_grpc_call : function () {},
50-
proxy_grpc_stream : function () {},
51-
proxy_grpc_send : function () {},
52-
proxy_grpc_close : function () {},
53-
proxy_grpc_cancel : function () {},
54-
proxy_send_local_response : function () {},
55-
proxy_set_effective_context : function () {},
56-
proxy_done: function () {},
57-
proxy_call_foreign_function: function () {},
19+
proxy_get_configuration: function() {},
20+
proxy_log: function() {},
21+
proxy_set_tick_period_milliseconds: function() {},
22+
proxy_get_current_time_nanoseconds: function() {},
23+
proxy_get_status: function() {},
24+
proxy_get_property: function() {},
25+
proxy_set_property: function() {},
26+
proxy_continue_stream: function() {},
27+
proxy_close_stream: function() {},
28+
proxy_clear_route_cache: function() {},
29+
proxy_add_header_map_value: function() {},
30+
proxy_get_header_map_value: function() {},
31+
proxy_get_header_map_pairs: function() {},
32+
proxy_get_header_map_size: function() {},
33+
proxy_get_shared_data: function() {},
34+
proxy_set_shared_data: function() {},
35+
proxy_register_shared_queue: function() {},
36+
proxy_resolve_shared_queue: function() {},
37+
proxy_enqueue_shared_queue: function() {},
38+
proxy_dequeue_shared_queue: function() {},
39+
proxy_replace_header_map_value: function() {},
40+
proxy_remove_header_map_value: function() {},
41+
proxy_get_buffer_bytes: function() {},
42+
proxy_get_buffer_status: function() {},
43+
proxy_set_buffer_bytes: function() {},
44+
proxy_http_call: function() {},
45+
proxy_define_metric: function() {},
46+
proxy_increment_metric: function() {},
47+
proxy_record_metric: function() {},
48+
proxy_get_metric: function() {},
49+
proxy_grpc_call: function() {},
50+
proxy_grpc_stream: function() {},
51+
proxy_grpc_send: function() {},
52+
proxy_grpc_close: function() {},
53+
proxy_grpc_cancel: function() {},
54+
proxy_send_local_response: function() {},
55+
proxy_set_effective_context: function() {},
56+
proxy_done: function() {},
57+
proxy_call_foreign_function: function() {},
5858
});

0 commit comments

Comments
 (0)