@@ -47,7 +47,8 @@ void ngx_http_wasm_unload_plugin(void *plugin);
4747void *ngx_http_wasm_on_configure (void * plugin , const char * conf , size_t size );
4848void ngx_http_wasm_delete_plugin_ctx (void * hwp_ctx );
4949
50- ngx_int_t ngx_http_wasm_on_http (void * hwp_ctx , void * r , int type );
50+ ngx_int_t ngx_http_wasm_on_http (void * hwp_ctx , void * r , int type ,
51+ const u_char * body , size_t size , int end_of_body );
5152ngx_str_t *ngx_http_wasm_fetch_local_body (void * r );
5253
5354ngx_int_t ngx_http_wasm_call_max_headers_count (void * r );
@@ -65,7 +66,7 @@ local ngx_table_size = ffi.sizeof("proxy_wasm_table_elt_t")
6566
6667local _M = {}
6768local HTTP_REQUEST_HEADERS = 1
68- -- local HTTP_REQUEST_BODY = 2
69+ local HTTP_REQUEST_BODY = 2
6970local HTTP_RESPONSE_HEADERS = 4
7071-- local HTTP_RESPONSE_BODY = 8
7172
@@ -258,7 +259,7 @@ local function handle_http_callback(plugin_ctx, r, res)
258259end
259260
260261
261- function _M . on_http_request_headers (plugin_ctx )
262+ local function on_http_request (plugin_ctx , ty , body , end_of_body )
262263 if type (plugin_ctx ) ~= " cdata" then
263264 return nil , " bad plugin ctx"
264265 end
@@ -268,9 +269,23 @@ function _M.on_http_request_headers(plugin_ctx)
268269 return nil , " bad request"
269270 end
270271
271- local rc = C .ngx_http_wasm_on_http (plugin_ctx , r , HTTP_REQUEST_HEADERS )
272+ local err
273+ if ty == HTTP_REQUEST_HEADERS then
274+ err = " failed to run proxy_on_http_request_headers"
275+ else
276+ err = " failed to run proxy_on_http_request_body"
277+ end
278+
279+ local body_size
280+ if not body then
281+ body_size = 0
282+ else
283+ body_size = # body
284+ end
285+
286+ local rc = C .ngx_http_wasm_on_http (plugin_ctx , r , ty , body , body_size , end_of_body )
272287 if rc < 0 then
273- return nil , " failed to run proxy_on_http_request_headers "
288+ return nil , err
274289 end
275290
276291 while true do
@@ -304,6 +319,16 @@ function _M.on_http_request_headers(plugin_ctx)
304319end
305320
306321
322+ function _M .on_http_request_headers (plugin_ctx )
323+ return on_http_request (plugin_ctx , HTTP_REQUEST_HEADERS , nil , 1 )
324+ end
325+
326+
327+ function _M .on_http_request_body (plugin_ctx , body , end_of_body )
328+ return on_http_request (plugin_ctx , HTTP_REQUEST_BODY , body , end_of_body and 1 or 0 )
329+ end
330+
331+
307332function _M .on_http_response_headers (plugin_ctx )
308333 if type (plugin_ctx ) ~= " cdata" then
309334 return nil , " bad plugin ctx"
@@ -314,7 +339,7 @@ function _M.on_http_response_headers(plugin_ctx)
314339 return nil , " bad request"
315340 end
316341
317- local rc = C .ngx_http_wasm_on_http (plugin_ctx , r , HTTP_RESPONSE_HEADERS )
342+ local rc = C .ngx_http_wasm_on_http (plugin_ctx , r , HTTP_RESPONSE_HEADERS , nil , 0 , 1 )
318343 if rc < 0 then
319344 return nil , " failed to run proxy_on_http_response_headers"
320345 end
0 commit comments