|
4 | 4 | #include "ngx_http_repsheet_xff.h"
|
5 | 5 | #include "ngx_http_repsheet_lookup.h"
|
6 | 6 |
|
7 |
| -static int |
8 |
| -flag_request(ngx_http_request_t *r, char *reason) |
9 |
| -{ |
10 |
| - repsheet_ctx_t *ctx; |
11 |
| - ctx = ngx_pcalloc(r->pool, sizeof(repsheet_ctx_t)); |
12 |
| - if (ctx == NULL) { |
13 |
| - return NGX_ERROR; |
14 |
| - } |
15 |
| - |
16 |
| - ngx_http_set_ctx(r, ctx, ngx_http_repsheet_module); |
17 |
| - |
18 |
| - ctx->flagged = 1; |
19 |
| - |
20 |
| - int len = strlen(reason); |
21 |
| - ctx->reason.len = len; |
22 |
| - ctx->reason.data = ngx_palloc(r->pool, len); |
23 |
| - if (ctx->reason.data == NULL) { |
24 |
| - return NGX_ERROR; |
25 |
| - } |
26 |
| - |
27 |
| - memcpy(ctx->reason.data, reason, len); |
28 |
| - |
29 |
| - return NGX_OK; |
| 7 | +void set_reason_header(ngx_http_request_t *r, ngx_str_t *reason) { |
| 8 | + ngx_table_elt_t *h; |
| 9 | + h = ngx_list_push(&r->headers_in.headers); |
| 10 | + h->hash = 1; |
| 11 | + ngx_str_set(&h->key, "X-Repsheet"); |
| 12 | + h->value.data = reason->data; |
| 13 | + h->value.len = reason->len; |
30 | 14 | }
|
31 | 15 |
|
32 | 16 | ngx_int_t lookup_ip(ngx_http_request_t *r, repsheet_main_conf_t *main_conf, repsheet_loc_conf_t *loc_conf)
|
@@ -58,10 +42,10 @@ ngx_int_t lookup_ip(ngx_http_request_t *r, repsheet_main_conf_t *main_conf, reps
|
58 | 42 |
|
59 | 43 | if (is_ip_marked(lookup_result)) {
|
60 | 44 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[Repsheet] - IP %s was found on repsheet. Reason: %s", address, reason);
|
61 |
| - if (flag_request(r, reason) != NGX_OK) { |
62 |
| - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[Repsheet] - failed to flag request"); |
63 |
| - return NGX_DECLINED; |
64 |
| - } |
| 45 | + ngx_str_t value; |
| 46 | + ngx_memcpy(value.data, reason, ngx_strlen(reason)); |
| 47 | + value.len = ngx_strlen(reason); |
| 48 | + set_reason_header(r, &value); |
65 | 49 | }
|
66 | 50 |
|
67 | 51 | if (lookup_result == WHITELISTED) {
|
|
0 commit comments