Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:FRiCKLE/ngx_coolkit

  • Loading branch information...
commit 3775c609bc1209c92d1b140271865a96e2c1126a 2 parents e7dcda9 + 4c57765
@agentzh agentzh authored
View
5 README
@@ -21,6 +21,11 @@ CONFIGURATION VARIABLES:
Decoded password from "Authorization" header (Basic HTTP Authentication).
+ $location
+ ---------
+ Name of the matched location block.
+
+
EXAMPLE CONFIGURATION #1:
-------------------------
http {
View
4 src/ngx_coolkit_module.c
@@ -47,6 +47,10 @@ static ngx_http_variable_t ngx_coolkit_module_variables[] = {
ngx_coolkit_variable_remote_passwd, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0 },
+ { ngx_string("location"), NULL,
+ ngx_coolkit_variable_location, 0,
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
View
33 src/ngx_coolkit_variables.c
@@ -57,3 +57,36 @@ ngx_coolkit_variable_remote_passwd(ngx_http_request_t *r,
return NGX_OK;
}
+
+
+ngx_int_t
+ngx_coolkit_variable_location(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_http_core_loc_conf_t *clcf;
+ ngx_int_t rc;
+ int captures[3];
+
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (clcf->regex) {
+ rc = ngx_regex_exec(clcf->regex->regex, &r->uri, captures, 3);
+
+ if (rc == NGX_REGEX_NO_MATCHED) {
+ return NGX_ERROR;
+ }
+
+ v->data = r->uri.data + captures[0];
+ v->len = captures[1] - captures[0];
+
+ } else {
+ v->data = clcf->name.data;
+ v->len = clcf->name.len;
+ }
+
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ return NGX_OK;
+}
View
2  src/ngx_coolkit_variables.h
@@ -33,5 +33,7 @@
ngx_int_t ngx_coolkit_variable_remote_passwd(ngx_http_request_t *,
ngx_http_variable_value_t *, uintptr_t);
+ngx_int_t ngx_coolkit_variable_location(ngx_http_request_t *,
+ ngx_http_variable_value_t *, uintptr_t);
#endif /* _NGX_COOLKIT_VARIABLES_H_ */
View
45 t/location.t
@@ -0,0 +1,45 @@
+# vi:filetype=perl
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+
+plan tests => repeat_each() * (blocks() * 3);
+
+worker_connections(128);
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: sanity
+--- config
+ location /echo {
+ echo -n $location;
+ }
+--- request
+GET /echo
+--- error_code: 200
+--- response_headers
+Content-Type: text/plain
+--- response_body chop
+/echo
+--- timeout: 10
+
+
+
+=== TEST 2: regex
+--- config
+ location ~/echo {
+ echo -n $location;
+ }
+--- request
+GET /test/echo/regex
+--- error_code: 200
+--- response_headers
+Content-Type: text/plain
+--- response_body chop
+/echo
+--- timeout: 10
Please sign in to comment.
Something went wrong with that request. Please try again.