Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2006-04-07 18:08:04 +0400
committerIgor Sysoev <igor@sysoev.ru>2006-04-07 18:08:04 +0400
commit94e32ce7f885ecc648ae6377276f8813fc1c9347 (patch)
tree88da0722e206c60326b466b85ab118c00be13f55 /src/http/modules
parent7469680c6c32901e7b6082a0e564430b587bbcfa (diff)
nginx-0.3.37-RELEASE importrelease-0.3.37
*) Feature: the "limit_except" directive. *) Feature: the "if" directive supports the "!~", "!~*", "-f", and "!-f" operators. *) Feature: the ngx_http_perl_module supports the $r->request_body method. *) Bugfix: in the ngx_http_addition_filter_module.
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_access_module.c6
-rw-r--r--src/http/modules/ngx_http_addition_filter_module.c24
-rw-r--r--src/http/modules/ngx_http_auth_basic_module.c7
-rw-r--r--src/http/modules/ngx_http_referer_module.c2
-rw-r--r--src/http/modules/ngx_http_rewrite_module.c76
-rw-r--r--src/http/modules/perl/nginx.xs35
6 files changed, 118 insertions, 32 deletions
diff --git a/src/http/modules/ngx_http_access_module.c b/src/http/modules/ngx_http_access_module.c
index 0e3430385..710dd248e 100644
--- a/src/http/modules/ngx_http_access_module.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -35,14 +35,16 @@ static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
static ngx_command_t ngx_http_access_commands[] = {
{ ngx_string("allow"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
+ |NGX_CONF_TAKE1,
ngx_http_access_rule,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("deny"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
+ |NGX_CONF_TAKE1,
ngx_http_access_rule,
NGX_HTTP_LOC_CONF_OFFSET,
0,
diff --git a/src/http/modules/ngx_http_addition_filter_module.c b/src/http/modules/ngx_http_addition_filter_module.c
index efd622e5a..842124d91 100644
--- a/src/http/modules/ngx_http_addition_filter_module.c
+++ b/src/http/modules/ngx_http_addition_filter_module.c
@@ -16,8 +16,7 @@ typedef struct {
typedef struct {
- unsigned before_body_sent:1;
- unsigned after_body_sent:1;
+ ngx_uint_t before_body_sent;
} ngx_http_addition_ctx_t;
@@ -92,6 +91,12 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
+
+ if (conf->before_body.len == 0 && conf->after_body.len == 0) {
+ return ngx_http_next_header_filter(r);
+ }
+
if (ngx_strncasecmp(r->headers_out.content_type.data, "text/html",
sizeof("text/html") - 1)
!= 0)
@@ -99,12 +104,6 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
-
- if (conf->before_body.len == 0 && conf->after_body.len == 0) {
- return ngx_http_next_header_filter(r);
- }
-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
@@ -155,17 +154,14 @@ ngx_http_addition_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
for (cl = in; cl; cl = cl->next) {
if (cl->buf->last_buf) {
cl->buf->last_buf = 0;
+ cl->buf->sync = 1;
last = 1;
}
}
rc = ngx_http_next_body_filter(r, in);
- if (rc == NGX_ERROR
- || !last
- || ctx->after_body_sent
- || conf->after_body.len == 0)
- {
+ if (rc == NGX_ERROR || !last || conf->after_body.len == 0) {
return rc;
}
@@ -173,7 +169,7 @@ ngx_http_addition_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_ERROR;
}
- ctx->after_body_sent = 1;
+ ngx_http_set_ctx(r, NULL, ngx_http_addition_filter_module);
return ngx_http_send_special(r, NGX_HTTP_LAST);
}
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
index 48192cad1..d33e7f6cf 100644
--- a/src/http/modules/ngx_http_auth_basic_module.c
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -41,14 +41,16 @@ static ngx_conf_post_handler_pt ngx_http_auth_basic_p = ngx_http_auth_basic;
static ngx_command_t ngx_http_auth_basic_commands[] = {
{ ngx_string("auth_basic"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
+ |NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_basic_loc_conf_t, realm),
&ngx_http_auth_basic_p },
{ ngx_string("auth_basic_user_file"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
+ |NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_basic_loc_conf_t, user_file),
@@ -58,7 +60,6 @@ static ngx_command_t ngx_http_auth_basic_commands[] = {
};
-
ngx_http_module_t ngx_http_auth_basic_module_ctx = {
NULL, /* preconfiguration */
NULL, /* postconfiguration */
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
index 3ad419b39..eb01857ab 100644
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -217,7 +217,7 @@ ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent, void *child)
}
if ((conf->no_referer == 1 || conf->blocked_referer == 1)
- && conf->keys->keys.nelts == 0 && conf->keys->dns_wildcards.nelts)
+ && conf->keys->keys.nelts == 0 && conf->keys->dns_wildcards.nelts == 0)
{
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"the \"none\" or \"blocked\" referers are specified "
diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
index 2c895c520..5709b5652 100644
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -578,7 +578,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
elts = lcf->codes->elts;
- /* the inside directives must compile to the same code array */
+ /* the inner directives must be compiled to the same code array */
nlcf = ctx->loc_conf[ngx_http_rewrite_module.ctx_index];
nlcf->codes = lcf->codes;
@@ -629,9 +629,12 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
{
+ u_char *p;
+ size_t len;
ngx_str_t *value, err;
ngx_uint_t cur, last, n;
ngx_http_script_code_pt *code;
+ ngx_http_script_file_code_t *fop;
ngx_http_script_regex_code_t *regex;
u_char errstr[NGX_MAX_CONF_ERRSTR];
@@ -667,11 +670,14 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
value[last].data[value[last].len] = '\0';
}
- if (value[cur].len > 1 && value[cur].data[0] == '$') {
+ len = value[cur].len;
+ p = value[cur].data;
+
+ if (len > 1 && p[0] == '$') {
if (cur != last && cur + 2 != last) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid condition \"%V\"", &value[cur]);
+ "invalid condition \"%V\"", &value[cur]);
return NGX_CONF_ERROR;
}
@@ -685,7 +691,10 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
cur++;
- if (value[cur].len == 1 && value[cur].data[0] == '=') {
+ len = value[cur].len;
+ p = value[cur].data;
+
+ if (len == 1 && p[0] == '=') {
if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
return NGX_CONF_ERROR;
@@ -702,9 +711,8 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
return NGX_CONF_OK;
}
- if (value[cur].len == 2
- && value[cur].data[0] == '!' && value[cur].data[1] == '=')
- {
+ if (len == 2 && p[0] == '!' && p[1] == '=') {
+
if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
return NGX_CONF_ERROR;
}
@@ -719,9 +727,10 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
return NGX_CONF_OK;
}
- if ((value[cur].len == 1 && value[cur].data[0] == '~')
- || (value[cur].len == 2
- && value[cur].data[0] == '~' && value[cur].data[1] == '*'))
+ if ((len == 1 && p[0] == '~')
+ || (len == 2 && p[0] == '~' && p[1] == '*')
+ || (len == 2 && p[0] == '!' && p[1] == '~')
+ || (len == 3 && p[0] == '!' && p[1] == '~' && p[2] == '*'))
{
regex = ngx_http_script_start_code(cf->pool, &lcf->codes,
sizeof(ngx_http_script_regex_code_t));
@@ -735,8 +744,8 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
err.data = errstr;
regex->regex = ngx_regex_compile(&value[last],
- (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0,
- cf->pool, &err);
+ (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0,
+ cf->pool, &err);
if (regex->regex == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
@@ -746,6 +755,9 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
regex->code = ngx_http_script_regex_start_code;
regex->next = sizeof(ngx_http_script_regex_code_t);
regex->test = 1;
+ if (p[0] == '!') {
+ regex->negative_test = 1;
+ }
regex->name = value[last];
n = ngx_regex_capture_count(regex->regex);
@@ -764,6 +776,46 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"unexpected \"%V\" in condition", &value[cur]);
return NGX_CONF_ERROR;
+
+ } else if ((len == 2 && p[0] == '-')
+ || (len == 3 && p[0] == '!' && p[1] == '-'))
+ {
+ if (cur + 1 != last) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+ return NGX_CONF_ERROR;
+ }
+
+ value[last].data[value[last].len] = '\0';
+ value[last].len++;
+
+ if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ fop = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_script_file_code_t));
+ if (fop == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ fop->code = ngx_http_script_file_code;
+
+ if (p[1] == 'f') {
+ fop->op = ngx_http_script_file_plain;
+ return NGX_CONF_OK;
+ }
+
+ if (p[0] == '!') {
+ if (p[2] == 'f') {
+ fop->op = ngx_http_script_file_not_plain;
+ return NGX_CONF_OK;
+ }
+ }
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+ return NGX_CONF_ERROR;
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
index d0453ea8d..7e2cec30e 100644
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -261,6 +261,41 @@ header_in(r, key)
RETVAL
+SV *
+request_body(r)
+ nginx r
+
+ PREINIT:
+
+ STRLEN len;
+ ngx_chain_t *cl;
+
+ CODE:
+
+ len = 0;
+
+ for (cl = r->request_body->bufs; cl; cl = cl->next) {
+ if (cl->buf->in_file) {
+ XSRETURN_UNDEF;
+ }
+
+ len += cl->buf->last - cl->buf->pos;
+ }
+
+ if (len == 0) {
+ XSRETURN_UNDEF;
+ }
+
+ RETVAL = newSV(len);
+
+ for (cl = r->request_body->bufs; cl; cl = cl->next) {
+ sv_catpvn(RETVAL, cl->buf->pos, cl->buf->last - cl->buf->pos);
+ }
+
+ OUTPUT:
+ RETVAL
+
+
int
header_out(r, key, value)
nginx r