Permalink
Browse files

Restore $uri variable in subrequests

  • Loading branch information...
Valery Kholodkov
Valery Kholodkov committed Jan 18, 2010
1 parent 9a8e8ab commit 11f7161db92bf811f467ede1f64ec56bd0fd5ee4
Showing with 35 additions and 3 deletions.
  1. +3 −0 Changelog
  2. +32 −3 ngx_http_eval_module.c
View
@@ -0,0 +1,3 @@
+
+Version 1.0.2
+ * Change: restore $uri variable in subrequests
View
@@ -120,13 +120,31 @@ ngx_module_t ngx_http_eval_module = {
static ngx_int_t
ngx_http_eval_handler(ngx_http_request_t *r)
{
+ size_t loc_len;
ngx_str_t args;
+ ngx_str_t subrequest_uri;
ngx_uint_t flags;
+ ngx_http_core_loc_conf_t *clcf;
ngx_http_eval_loc_conf_t *ecf;
ngx_http_eval_ctx_t *ctx;
ngx_http_request_t *sr;
ngx_int_t rc;
ngx_http_post_subrequest_t *psr;
+ u_char *p;
+
+ if(r != r->main) {
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ loc_len = r->valid_location ? clcf->name.len : 0;
+
+ if(r->uri.len != loc_len) {
+ r->uri.data += loc_len;
+ r->uri.len -= loc_len;
+ }
+ else {
+ r->uri.len = 1;
+ }
+ }
ecf = ngx_http_get_module_loc_conf(r, ngx_http_eval_module);
@@ -172,7 +190,18 @@ ngx_http_eval_handler(ngx_http_request_t *r)
args.data = NULL;
flags = 0;
- if (ngx_http_parse_unsafe_uri(r, &ecf->eval_location, &args, &flags) != NGX_OK) {
+ subrequest_uri.len = ecf->eval_location.len + r->uri.len;
+
+ p = subrequest_uri.data = ngx_palloc(r->pool, subrequest_uri.len);
+
+ if(p == NULL) {
+ return NGX_ERROR;
+ }
+
+ p = ngx_copy(p, ecf->eval_location.data, ecf->eval_location.len);
+ p = ngx_copy(p, r->uri.data, r->uri.len);
+
+ if (ngx_http_parse_unsafe_uri(r, &subrequest_uri, &args, &flags) != NGX_OK) {
return NGX_ERROR;
}
@@ -181,7 +210,7 @@ ngx_http_eval_handler(ngx_http_request_t *r)
flags |= NGX_HTTP_SUBREQUEST_IN_MEMORY|NGX_HTTP_SUBREQUEST_WAITED;
- rc = ngx_http_subrequest(r, &ecf->eval_location, &args, &sr, psr, flags);
+ rc = ngx_http_subrequest(r, &subrequest_uri, &args, &sr, psr, flags);
if (rc == NGX_ERROR || rc == NGX_DONE) {
return rc;
@@ -585,7 +614,7 @@ ngx_http_eval_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
clcf->loc_conf = ctx->loc_conf;
clcf->name = name;
- clcf->exact_match = 1;
+ clcf->exact_match = 0;
clcf->noname = 0;
clcf->internal = 1;
clcf->noregex = 1;

0 comments on commit 11f7161

Please sign in to comment.