Skip to content

Commit

Permalink
Remove the reason variable, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Dec 1, 2018
1 parent 99947e7 commit e699698
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 87 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ http {
repsheet_proxy_headers_header "True-Client-IP";
repsheet_proxy_fallback on;
proxy_set_header X-Repsheet $repsheet;
server {
listen 8888;
location / {
Expand All @@ -67,12 +65,6 @@ http {
}
```

Notice the `proxy_set_header` directive. This is placed in the
configuration when applying marking. The module will populate the
`$repsheet` variable when a mark needs to be applied, and it will also
populate the `$repsheet_reason` variable with the reason for the
marking.

## Running the Integration Tests

This project comes with a basic set of integration tests to ensure
Expand Down
2 changes: 0 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ http {
repsheet_proxy_headers_header "X-Forwarded-For";
repsheet_proxy_headers_fallback on;

proxy_set_header X-Repsheet $repsheet;

upstream app {
server localhost:4567;
}
Expand Down
85 changes: 8 additions & 77 deletions ngx_http_repsheet_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,6 @@
#include "ngx_http_repsheet_cache.h"
#include "ngx_http_repsheet_xff.h"

ngx_str_t ngx_http_repsheet_variable_name = ngx_string("repsheet");
ngx_str_t ngx_http_repsheet_flagged = ngx_string("true");
ngx_str_t ngx_http_repsheet_default = ngx_string("");
ngx_str_t ngx_http_repsheet_reason_variable_name = ngx_string("repsheet_reason");


static ngx_int_t
ngx_http_repsheet_reason_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data)
{
repsheet_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_repsheet_module);

if (ctx && ctx->reason.data) {
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->len = ctx->reason.len;
v->data = ctx->reason.data;
} else {
v->not_found = 1;
}

return NGX_OK;
}


static ngx_int_t
ngx_http_repsheet_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data)
{
repsheet_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_repsheet_module);

if (ctx && ctx->flagged) {
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->len = ngx_http_repsheet_flagged.len;
v->data = ngx_http_repsheet_flagged.data;
} else {
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->len = ngx_http_repsheet_default.len;
v->data = ngx_http_repsheet_default.data;
}

return NGX_OK;
}


static int
flag_request(ngx_http_request_t *r, char *reason)
Expand Down Expand Up @@ -80,28 +33,6 @@ flag_request(ngx_http_request_t *r, char *reason)
}


static ngx_int_t
ngx_http_repsheet_preconf_add_variables(ngx_conf_t *cf)
{
ngx_http_variable_t *var;
var = ngx_http_add_variable(cf, &ngx_http_repsheet_variable_name, NGX_HTTP_VAR_NOCACHEABLE);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_repsheet_variable;
var->data = 0;

var = ngx_http_add_variable(cf, &ngx_http_repsheet_reason_variable_name, NGX_HTTP_VAR_NOCACHEABLE);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_repsheet_reason_variable;
var->data = 0;

return NGX_OK;
}


static ngx_int_t
lookup_ip(ngx_http_request_t *r, repsheet_main_conf_t *main_conf, repsheet_loc_conf_t *loc_conf)
{
Expand Down Expand Up @@ -330,14 +261,14 @@ ngx_http_repsheet_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)


static ngx_http_module_t ngx_http_repsheet_module_ctx = {
ngx_http_repsheet_preconf_add_variables, /* preconfiguration */
ngx_http_repsheet_init, /* postconfiguration */
ngx_http_repsheet_create_main_conf, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_http_repsheet_create_loc_conf, /* create location configuration */
ngx_http_repsheet_merge_loc_conf /* merge location configuration */
NULL, /* preconfiguration */
ngx_http_repsheet_init, /* postconfiguration */
ngx_http_repsheet_create_main_conf, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_http_repsheet_create_loc_conf, /* create location configuration */
ngx_http_repsheet_merge_loc_conf /* merge location configuration */
};


Expand Down

0 comments on commit e699698

Please sign in to comment.