summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_request.c
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2023-07-19 13:36:59 +0200
committerAlejandro Colomar <alx@nginx.com>2023-09-03 18:38:05 +0200
commit4977d280cacc7dd2bbbd61a00d133574f18cb118 (patch)
treec63e0b8b40a774b3e30e4e0bbb6b3fb2ecc81f1d /src/nxt_http_request.c
parentecc27ab1d4adba7223beb3b122f9b041ab6ae323 (diff)
downloadunit-4977d280cacc7dd2bbbd61a00d133574f18cb118.tar.gz
unit-4977d280cacc7dd2bbbd61a00d133574f18cb118.tar.bz2
HTTP: filter: supporting a list of filter_handlers
Filter handlers are a new handler that takes place when a buffer is about to be sent. It filters (modifies) the contents of the buffer in-place, so that the new contents will be sent. Several filters can be applied in a loop. Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to '')
-rw-r--r--src/nxt_http_request.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c
index 3bcf3d94..e72a7492 100644
--- a/src/nxt_http_request.c
+++ b/src/nxt_http_request.c
@@ -7,6 +7,8 @@
#include <nxt_router.h>
#include <nxt_http.h>
+#include "nxt_http_filter.h"
+
static nxt_int_t nxt_http_validate_host(nxt_str_t *host, nxt_mp_t *mp);
static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data);
@@ -262,6 +264,11 @@ nxt_http_request_create(nxt_task_t *task)
goto fail;
}
+ r->response_filters = nxt_list_create(mp, 1, sizeof(nxt_http_filter_handler_t));
+ if (nxt_slow_path(r->response_filters == NULL)) {
+ goto fail;
+ }
+
last = nxt_mp_zget(mp, NXT_BUF_SYNC_SIZE);
if (nxt_slow_path(last == NULL)) {
goto fail;
@@ -723,6 +730,12 @@ nxt_http_request_ws_frame_start(nxt_task_t *task, nxt_http_request_t *r,
void
nxt_http_request_send(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out)
{
+ nxt_http_filter_handler_t *filter;
+
+ nxt_list_each(filter, r->response_filters) {
+ filter->filter_handler(task, &out, filter->data);
+ } nxt_list_loop;
+
if (nxt_fast_path(r->proto.any != NULL)) {
nxt_http_proto[r->protocol].send(task, r, out);
}