Referer: fixed $invalid_referer.
The variable was considered non-existent in the absence of any
valid_referers directives.
Given the following config snippet,
location / {
return 200 $invalid_referer;
}
location /referer {
valid_referers server_names;
}
"location /" should work identically and independently on other
"location /referer".
The fix is to always add the $invalid_referer variable as long
as the module is compiled in, as is done by other modules.
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
index 3f0f78e..599dd3a 100644
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -32,6 +32,7 @@
} ngx_http_referer_conf_t;
+static ngx_int_t ngx_http_referer_add_variables(ngx_conf_t *cf);
static void * ngx_http_referer_create_conf(ngx_conf_t *cf);
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
void *child);
@@ -77,7 +78,7 @@
static ngx_http_module_t ngx_http_referer_module_ctx = {
- NULL, /* preconfiguration */
+ ngx_http_referer_add_variables, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
@@ -107,6 +108,9 @@
};
+static ngx_str_t ngx_http_invalid_referer_name = ngx_string("invalid_referer");
+
+
static ngx_int_t
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
@@ -263,6 +267,23 @@
}
+static ngx_int_t
+ngx_http_referer_add_variables(ngx_conf_t *cf)
+{
+ ngx_http_variable_t *var;
+
+ var = ngx_http_add_variable(cf, &ngx_http_invalid_referer_name,
+ NGX_HTTP_VAR_CHANGEABLE);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
+
+ var->get_handler = ngx_http_referer_variable;
+
+ return NGX_OK;
+}
+
+
static void *
ngx_http_referer_create_conf(ngx_conf_t *cf)
{
@@ -452,19 +473,9 @@
{
ngx_http_referer_conf_t *rlcf = conf;
- u_char *p;
- ngx_str_t *value, uri, name;
- ngx_uint_t i;
- ngx_http_variable_t *var;
-
- ngx_str_set(&name, "invalid_referer");
-
- var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
- if (var == NULL) {
- return NGX_CONF_ERROR;
- }
-
- var->get_handler = ngx_http_referer_variable;
+ u_char *p;
+ ngx_str_t *value, uri;
+ ngx_uint_t i;
if (rlcf->keys == NULL) {
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));