diff options
| author | Alejandro Colomar <alx@nginx.com> | 2023-07-19 13:36:59 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2023-10-25 13:37:55 +0200 |
| commit | ddb7d61f6173c2f191f4eddc15f1f912e940e42c (patch) | |
| tree | de151a557a3328dbfcf438bdf1abcca79d71709f /src/nxt_http_filter.h | |
| parent | 9be4b16f0c99a8dd2e56fa5cd2a153ad5683c2a3 (diff) | |
| download | unit-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_filter.h')
| -rw-r--r-- | src/nxt_http_filter.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/nxt_http_filter.h b/src/nxt_http_filter.h new file mode 100644 index 00000000..d26ae1a9 --- /dev/null +++ b/src/nxt_http_filter.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) Alejandro Colomar + * Copyright (C) NGINX, Inc. + */ + +#ifndef NXT_HTTP_FILTER_H_INCLUDED_ +#define NXT_HTTP_FILTER_H_INCLUDED_ + + +#include "nxt_router.h" + +#include "nxt_auto_config.h" + +#include <stddef.h> + +#include "nxt_clang.h" +#include "nxt_errno.h" +#include "nxt_list.h" +#include "nxt_main.h" + + +typedef struct nxt_http_filter_handler_s nxt_http_filter_handler_t; + + +struct nxt_http_filter_handler_s { + nxt_work_handler_t filter_handler; + void *data; +}; + + +nxt_inline nxt_int_t nxt_http_filter_handler_add(nxt_http_request_t *r, + nxt_work_handler_t filter_handler, void *data); + + +nxt_inline nxt_int_t +nxt_http_filter_handler_add(nxt_http_request_t *r, + nxt_work_handler_t filter_handler, void *data) +{ + nxt_http_filter_handler_t *elem; + + elem = nxt_list_add(r->response_filters); + if (nxt_slow_path(elem == NULL)) { + return NXT_ERROR; + } + + elem->filter_handler = filter_handler; + elem->data = data; + + return NXT_OK; +} + + +#endif /* NXT_HTTP_FILTER_H_INCLUDED_ */ |
