compilable

This commit is contained in:
hladu357 2024-05-15 13:41:57 +02:00
commit a3f3b143f4
2 changed files with 115 additions and 0 deletions

7
config Normal file
View File

@ -0,0 +1,7 @@
ngx_module_type=HTTP_AUX_FILTER
ngx_module_name=ngx_http_key_header_module
ngx_module_srcs="$ngx_addon_dir/http_key_header_module.c"
. auto/module
ngx_addon_name=$ngx_module_name

108
http_key_header_module.c Normal file
View File

@ -0,0 +1,108 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_int_t ngx_http_key_header_filter(ngx_http_request_t*);
static ngx_int_t ngx_http_key_header_init(ngx_conf_t*);
static void* ngx_http_key_header_create_conf(ngx_conf_t*);
static char* ngx_http_key_header_merge_loc_conf(ngx_conf_t*, void* parent, void* child);
typedef struct
{
ngx_flag_t enabled;
}
ngx_http_key_header_loc_conf_t;
static ngx_command_t
ngx_http_key_header_filter_commands[] =
{
{
ngx_string("send_cache_key"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_key_header_loc_conf_t, enabled),
NULL
},
ngx_null_command
};
static ngx_http_module_t
ngx_http_key_header_filter_module_ctx =
{
NULL, /* Pre config */
ngx_http_key_header_init, /* Post config */
NULL, /* Create main config */
NULL, /* Init main config */
NULL, /* Create server config */
NULL, /* Merge server config */
ngx_http_key_header_create_conf, /* Create loc config */
ngx_http_key_header_merge_loc_conf /* Merge loc config */
};
static ngx_int_t
ngx_http_key_header_init(ngx_conf_t*)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_key_header_filter;
return NGX_OK;
}
static void*
ngx_http_key_header_create_conf(ngx_conf_t *cf)
{
ngx_http_key_header_loc_conf_t *conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_key_header_loc_conf_t));
if(conf == NULL) {
return NGX_CONF_ERROR;
}
conf->enabled = NGX_CONF_UNSET;
return conf;
}
static char*
ngx_http_key_header_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_key_header_loc_conf_t *prev = parent;
ngx_http_key_header_loc_conf_t *conf = child;
ngx_conf_merge_value(conf->enabled, prev->enabled, 0);
return NGX_CONF_OK;
}
ngx_module_t ngx_http_key_header_module =
{
NGX_MODULE_V1,
&ngx_http_key_header_filter_module_ctx, /* module context */
ngx_http_key_header_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NGX_MODULE_V1_PADDING
};
static ngx_int_t
ngx_http_key_header_filter(ngx_http_request_t *r )
{
return ngx_http_next_header_filter(r);
}