changeset 1:dfc5ae42367a

Auth request: support switching off.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 26 Feb 2010 21:21:22 +0300
parents 436da5355bd5
children 187ac993cd15
files ngx_http_auth_request_module.c t/auth-request.t
diffstat 2 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ngx_http_auth_request_module.c	Sat Feb 20 14:30:30 2010 +0300
+++ b/ngx_http_auth_request_module.c	Fri Feb 26 21:21:22 2010 +0300
@@ -27,15 +27,17 @@
 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 @@
 
     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;
+}
--- a/t/auth-request.t	Sat Feb 20 14:30:30 2010 +0300
+++ b/t/auth-request.t	Fri Feb 26 21:21:22 2010 +0300
@@ -18,7 +18,7 @@
 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 @@
             return 404;
         }
 
+        location /off {
+            auth_request off;
+        }
+
         location /proxy {
             auth_request /auth-proxy;
         }
@@ -109,6 +113,7 @@
 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');