# HG changeset patch # User Maxim Dounin # Date 1267208482 -10800 # Node ID dfc5ae42367a0ef4675d24460015358b95c98e18 # Parent 436da5355bd5f50d680e3ef094bfa40138443203 Auth request: support switching off. diff --git a/ngx_http_auth_request_module.c b/ngx_http_auth_request_module.c --- a/ngx_http_auth_request_module.c +++ b/ngx_http_auth_request_module.c @@ -27,15 +27,17 @@ static void *ngx_http_auth_request_creat static char *ngx_http_auth_request_merge_conf(ngx_conf_t *cf, void *parent, void *child); static ngx_int_t ngx_http_auth_request_init(ngx_conf_t *cf); +static char *ngx_http_auth_request(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static ngx_command_t ngx_http_auth_request_commands[] = { { ngx_string("auth_request"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_str_slot, + ngx_http_auth_request, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_auth_request_conf_t, uri), + 0, NULL }, ngx_null_command @@ -231,3 +233,29 @@ ngx_http_auth_request_init(ngx_conf_t *c return NGX_OK; } + + +static char * +ngx_http_auth_request(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_http_auth_request_conf_t *arcf = conf; + + ngx_str_t *value; + + if (arcf->uri.data != NULL) { + return "is duplicate"; + } + + value = cf->args->elts; + + if (ngx_strcmp(value[1].data, "off") == 0) { + arcf->uri.len = 0; + arcf->uri.data = (u_char *) ""; + + return NGX_CONF_OK; + } + + arcf->uri = value[1]; + + return NGX_CONF_OK; +} diff --git a/t/auth-request.t b/t/auth-request.t --- a/t/auth-request.t +++ b/t/auth-request.t @@ -18,7 +18,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http rewrite proxy fastcgi auth_basic/) - ->plan(13); + ->plan(14); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -74,6 +74,10 @@ http { return 404; } + location /off { + auth_request off; + } + location /proxy { auth_request /auth-proxy; } @@ -109,6 +113,7 @@ like(http_get('/open'), qr/ 404 /, 'auth like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized'); like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden'); like(http_get('/error'), qr/ 500 /, 'auth error'); +like(http_get('/off'), qr/ 404 /, 'auth off'); like(http_get('/open-static'), qr/ 404 /, 'auth open static'); unlike(http_get('/open-static'), qr/INVISIBLE/, 'auth static no content');