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@kernel.org>2023-10-25 13:37:55 +0200
commitddb7d61f6173c2f191f4eddc15f1f912e940e42c (patch)
treede151a557a3328dbfcf438bdf1abcca79d71709f /src/nxt_http_request.c
parent9be4b16f0c99a8dd2e56fa5cd2a153ad5683c2a3 (diff)
downloadunit-ddb7d61f6173c2f191f4eddc15f1f912e940e42c.tar.gz
unit-ddb7d61f6173c2f191f4eddc15f1f912e940e42c.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> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'src/nxt_http_request.c')
-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);
}