-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopfa_http_remove_server_header_module.c
More file actions
69 lines (56 loc) · 2.03 KB
/
opfa_http_remove_server_header_module.c
File metadata and controls
69 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#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 opfa_http_remove_server_header_install_handler(ngx_conf_t *cf);
static ngx_int_t opfa_http_remove_server_header_handler(ngx_http_request_t *r);
static ngx_command_t opfa_http_remove_server_header_commands[] = {
ngx_null_command /* command termination */
};
/* The module context. */
static ngx_http_module_t opfa_http_remove_server_header_module_ctx = {
NULL, /* preconfiguration */
opfa_http_remove_server_header_install_handler, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
NULL, /* create location configuration */
NULL /* merge location configuration */
};
/* Module definition. */
ngx_module_t opfa_http_remove_server_header_module = {
NGX_MODULE_V1,
&opfa_http_remove_server_header_module_ctx, /* module context */
opfa_http_remove_server_header_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
static ngx_int_t opfa_http_remove_server_header_handler(ngx_http_request_t *r)
{
ngx_table_elt_t *h = r->headers_out.server;
if (h == NULL) {
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_ERROR;
}
ngx_str_set(&h->key, "Server");
ngx_str_set(&h->value, "");
r->headers_out.server = h;
}
h->hash = 0;
return ngx_http_next_header_filter(r);
}
static ngx_int_t opfa_http_remove_server_header_install_handler(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = opfa_http_remove_server_header_handler;
return NGX_OK;
}