diff src/http/modules/ngx_http_rewrite_module.c @ 54:bcb5fce0b038 NGINX_0_1_27

nginx 0.1.27 *) Feature: the "blocked" parameter of the "valid_referers" directive. *) Change: the errors while handling the request header now logged at "info" level. The server name and the "Host" and "Referer" header lines also logged. *) Change: the "Host" header line is also logged in error log. *) Feature: the proxy_pass_unparsed_uri directive. The special handling of the "://" symbols in URI, appeared in 0.1.11 version, now is canceled. *) Bugfix: nginx could not be built on FreeBSD and Linux, if the --without-ngx_http_auth_basic_module configuration parameter was used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 28 Mar 2005 00:00:00 +0400
parents 72eb30262aac
children 3050baa54a26
line wrap: on
line diff
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -36,6 +36,7 @@ typedef struct {
     ngx_flag_t                    log;
 
     ngx_flag_t                    no_referer;
+    ngx_flag_t                    blocked_referer;
 } ngx_http_rewrite_loc_conf_t;
 
 
@@ -378,6 +379,7 @@ ngx_http_rewrite_regex_start_code(ngx_ht
     if (code->uri) {
         if (!code->break_cycle) {
             r->uri_changed = 1;
+            r->valid_unparsed_uri = 1;
         }
 
         if (rc && (r->quoted_uri || r->plus_in_uri)) {
@@ -715,6 +717,7 @@ ngx_http_rewrite_invalid_referer_code(ng
             e->sp++;
 
             return;
+
         } else {
             e->sp->value = 1;
             e->sp->text.len = 1;
@@ -731,12 +734,22 @@ ngx_http_rewrite_invalid_referer_code(ng
     if (len < sizeof("http://i.ru") - 1
         || (ngx_strncasecmp(ref, "http://", 7) != 0))
     {
-        e->sp->value = 1;
-        e->sp->text.len = 1;
-        e->sp->text.data = (u_char *) "1";
-        e->sp++;
+        if (cf->blocked_referer) {
+            e->sp->value = 0;
+            e->sp->text.len = 0;
+            e->sp->text.data = (u_char *) "0";
+            e->sp++;
+
+            return;
 
-        return;
+        } else {
+            e->sp->value = 1;
+            e->sp->text.len = 1;
+            e->sp->text.data = (u_char *) "1";
+            e->sp++;
+
+            return;
+        }
     }
 
     len -= 7;
@@ -853,6 +866,7 @@ ngx_http_rewrite_create_loc_conf(ngx_con
     conf->stack_size = NGX_CONF_UNSET_UINT;
     conf->log = NGX_CONF_UNSET;
     conf->no_referer = NGX_CONF_UNSET;
+    conf->blocked_referer = NGX_CONF_UNSET;
 
     return conf;
 }
@@ -873,12 +887,17 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf
     if (conf->referers == NULL) {
         conf->referers = prev->referers;
         ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
+        ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0);
     }
 
     if (conf->no_referer == NGX_CONF_UNSET) {
         conf->no_referer = 0;
     }
 
+    if (conf->blocked_referer == NGX_CONF_UNSET) {
+        conf->blocked_referer = 0;
+    }
+
     if (conf->codes == NULL) {
         return NGX_CONF_OK;
     }
@@ -1540,6 +1559,11 @@ ngx_http_rewrite_valid_referers(ngx_conf
             continue;
         }
 
+        if (ngx_strcmp(value[i].data, "blocked") == 0) {
+            lcf->blocked_referer = 1;
+            continue;
+        }
+
         if (ngx_strcmp(value[i].data, "server_names") == 0) {
             server_names = 1;
             continue;