]> git.pld-linux.org Git - packages/lighttpd.git/blame_incremental - lighttpd-mod_evasive-status_code.patch
add mod_vhostdb_pgsql build
[packages/lighttpd.git] / lighttpd-mod_evasive-status_code.patch
... / ...
CommitLineData
1--- lighttpd-1.4.19/src/mod_evasive.c 2008-09-19 17:50:24.307245276 +0300
2+++ lighttpd-1.4.22/src/mod_evasive.c 2009-05-12 02:21:58.524447939 +0300
3@@ -28,11 +28,15 @@
4 typedef struct {
5 unsigned short max_conns;
6 unsigned short silent;
7+ unsigned short http_status_code;
8+ unsigned int retry_after;
9 } plugin_config;
10
11 typedef struct {
12 PLUGIN_DATA;
13
14+ buffer *evasive_rftmp;
15+
16 plugin_config **config_storage;
17
18 plugin_config conf;
19@@ -46,6 +50,10 @@
20
21 p = calloc(1, sizeof(*p));
22
23+ p->evasive_rftmp = buffer_init();
24+
25+ buffer_prepare_copy(p->evasive_rftmp, 255);
26+
27 return p;
28 }
29
30@@ -56,6 +64,8 @@
31
32 if (!p) return HANDLER_GO_ON;
33
34+ buffer_free(p->evasive_rftmp);
35+
36 if (p->config_storage) {
37 size_t i;
38 for (i = 0; i < srv->config_context->used; i++) {
39@@ -85,6 +85,8 @@
40 config_values_t cv[] = {
41 { "evasive.max-conns-per-ip", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
42 { "evasive.silent", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
43+ { "evasive.http-status-code", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
44+ { "evasive.retry-after", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 3 */
45 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
46 };
47
48@@ -94,11 +96,15 @@
49 plugin_config *s;
50
51 s = calloc(1, sizeof(plugin_config));
52- s->max_conns = 0;
53- s->silent = 0;
54+ s->max_conns = 0;
55+ s->silent = 0;
56+ s->http_status_code = 503;
57+ s->retry_after = 0;
58
59 cv[0].destination = &(s->max_conns);
60 cv[1].destination = &(s->silent);
61+ cv[2].destination = &(s->http_status_code);
62+ cv[3].destination = &(s->retry_after);
63
64 p->config_storage[i] = s;
65
66@@ -107,6 +123,8 @@
67
68 PATCH(max_conns);
69 PATCH(silent);
70+ PATCH(http_status_code);
71+ PATCH(retry_after);
72
73 /* skip the first, the global context */
74 for (i = 1; i < srv->config_context->used; i++) {
75@@ -124,6 +142,10 @@
76 PATCH(max_conns);
77 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.silent"))) {
78 PATCH(silent);
79+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.http-status-code"))) {
80+ PATCH(http_status_code);
81+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.retry-after"))) {
82+ PATCH(retry_after);
83 }
84 }
85 }
86@@ -192,8 +214,10 @@
87 inet_ntop_cache_get_ip(srv, &(con->dst_addr)),
88 "turned away. Too many connections.");
89
90- con->http_status = 403;
91 con->mode = DIRECT;
92+ con->http_status = p->conf.http_status_code;
93+ buffer_copy_long(p->evasive_rftmp, p->conf.retry_after);
94+ response_header_overwrite(srv, con, CONST_STR_LEN("Retry-After"), CONST_BUF_LEN(p->evasive_rftmp));
95 return HANDLER_FINISHED;
96 }
97 }
This page took 0.021526 seconds and 4 git commands to generate.