changeset 3661:8649a0c0f09d

change logic introduced in r3649: *) now $uid_set is cacheable again *) allow to see at any processing stage that uid cookie is remarked
author Igor Sysoev <igor@sysoev.ru>
date Wed, 30 Jun 2010 14:30:55 +0000
parents 564b4ca17cb3
children a870639d2970
files src/http/modules/ngx_http_userid_filter_module.c
diffstat 1 files changed, 34 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -211,21 +211,6 @@ ngx_http_userid_filter(ngx_http_request_
         return NGX_ERROR;
     }
 
-    if (ctx->uid_got[3] != 0) {
-
-        if (conf->mark == '\0') {
-            return ngx_http_next_header_filter(r);
-
-        } else {
-            if (ctx->cookie.len > 23
-                && ctx->cookie.data[22] == conf->mark
-                && ctx->cookie.data[23] == '=')
-            {
-                return ngx_http_next_header_filter(r);
-            }
-        }
-    }
-
     if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) {
         return ngx_http_next_header_filter(r);
     }
@@ -284,16 +269,13 @@ ngx_http_userid_set_variable(ngx_http_re
         return NGX_ERROR;
     }
 
-    if (ctx->uid_set[3] == 0) {
+    if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
+        return NGX_ERROR;
+    }
 
-        if (ctx->uid_got[3] != 0) {
-            v->not_found = 1;
-            return NGX_OK;
-        }
-
-        if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
-            return NGX_ERROR;
-        }
+    if (ctx->uid_set[3] == 0) {
+        v->not_found = 1;
+        return NGX_OK;
     }
 
     return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set);
@@ -379,18 +361,12 @@ ngx_http_userid_set_uid(ngx_http_request
     ngx_str_t         src, dst;
     ngx_table_elt_t  *set_cookie, *p3p;
 
-    if (ctx->uid_set[3] == 0) {
-        if (ctx->uid_got[3] == 0) {
-            if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
-                return NGX_ERROR;
-            }
+    if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
+        return NGX_ERROR;
+    }
 
-        } else {
-            ctx->uid_set[0] = ctx->uid_got[0];
-            ctx->uid_set[1] = ctx->uid_got[1];
-            ctx->uid_set[2] = ctx->uid_got[2];
-            ctx->uid_set[3] = ctx->uid_got[3];
-        }
+    if (ctx->uid_set[3] == 0) {
+        return NGX_OK;
     }
 
     len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
@@ -483,6 +459,28 @@ ngx_http_userid_create_uid(ngx_http_requ
     struct sockaddr_in6  *sin6;
 #endif
 
+    if (ctx->uid_set[3] != 0) {
+        return NGX_OK;
+    }
+
+    if (ctx->uid_got[3] != 0) {
+
+        if (conf->mark == '\0'
+            || (ctx->cookie.len > 23
+                && ctx->cookie.data[22] == conf->mark
+                && ctx->cookie.data[23] == '='))
+        {
+            return NGX_OK;
+        }
+
+        ctx->uid_set[0] = ctx->uid_got[0];
+        ctx->uid_set[1] = ctx->uid_got[1];
+        ctx->uid_set[2] = ctx->uid_got[2];
+        ctx->uid_set[3] = ctx->uid_got[3];
+
+        return NGX_OK;
+    }
+
     /*
      * TODO: in the threaded mode the sequencers should be in TLS and their
      * ranges should be divided between threads
@@ -579,8 +577,7 @@ ngx_http_userid_add_variables(ngx_conf_t
 
     var->get_handler = ngx_http_userid_got_variable;
 
-    var = ngx_http_add_variable(cf, &ngx_http_userid_set,
-                                NGX_HTTP_VAR_NOCACHEABLE);
+    var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0);
     if (var == NULL) {
         return NGX_ERROR;
     }