[PATCH] auth_request: add support 407 response

Andrey Burov burik666 at gmail.com
Mon Jul 27 14:14:39 UTC 2015


# HG changeset patch
# User Andrey Burov <burik666 at gmail.com>
# Date 1438003704 -10800
#      Mon Jul 27 16:28:24 2015 +0300
# Node ID 45362796f681e0d107810ba20781a859e6c03cf5
# Parent  341e4303d25be159d4773b819d0ec055ba711afb
auth_request: add support 407 response

Receive "Proxy-Authenticate" header for the 407 response from subrequest.

diff -r 341e4303d25b -r 45362796f681 src/http/modules/ngx_http_auth_request_module.c
--- a/src/http/modules/ngx_http_auth_request_module.c	Thu Jul 16 14:20:48 2015 +0300
+++ b/src/http/modules/ngx_http_auth_request_module.c	Mon Jul 27 16:28:24 2015 +0300
@@ -161,6 +161,29 @@
             return ctx->status;
         }
 
+        if (ctx->status == NGX_HTTP_PROXY_UNAUTHORIZED) {
+            sr = ctx->subrequest;
+
+            h = sr->headers_out.proxy_authenticate;
+
+            if (!h && sr->upstream) {
+                h = sr->upstream->headers_in.proxy_authenticate;
+            }
+
+            if (h) {
+                ho = ngx_list_push(&r->headers_out.headers);
+                if (ho == NULL) {
+                    return NGX_ERROR;
+                }
+
+                *ho = *h;
+
+                r->headers_out.proxy_authenticate = ho;
+            }
+
+            return ctx->status;
+        }
+
         if (ctx->status >= NGX_HTTP_OK
             && ctx->status < NGX_HTTP_SPECIAL_RESPONSE)
         {
diff -r 341e4303d25b -r 45362796f681 src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h	Thu Jul 16 14:20:48 2015 +0300
+++ b/src/http/ngx_http_request.h	Mon Jul 27 16:28:24 2015 +0300
@@ -86,6 +86,7 @@
 #define NGX_HTTP_FORBIDDEN                 403
 #define NGX_HTTP_NOT_FOUND                 404
 #define NGX_HTTP_NOT_ALLOWED               405
+#define NGX_HTTP_PROXY_UNAUTHORIZED        407
 #define NGX_HTTP_REQUEST_TIME_OUT          408
 #define NGX_HTTP_CONFLICT                  409
 #define NGX_HTTP_LENGTH_REQUIRED           411
@@ -256,6 +257,7 @@
     ngx_table_elt_t                  *content_range;
     ngx_table_elt_t                  *accept_ranges;
     ngx_table_elt_t                  *www_authenticate;
+    ngx_table_elt_t                  *proxy_authenticate;
     ngx_table_elt_t                  *expires;
     ngx_table_elt_t                  *etag;
 
diff -r 341e4303d25b -r 45362796f681 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c	Thu Jul 16 14:20:48 2015 +0300
+++ b/src/http/ngx_http_upstream.c	Mon Jul 27 16:28:24 2015 +0300
@@ -216,6 +216,11 @@
                  offsetof(ngx_http_upstream_headers_in_t, www_authenticate),
                  ngx_http_upstream_copy_header_line, 0, 0 },
 
+     { ngx_string("Proxy-Authenticate"),
+                 ngx_http_upstream_process_header_line,
+                 offsetof(ngx_http_upstream_headers_in_t, proxy_authenticate),
+                 ngx_http_upstream_copy_header_line, 0, 0 },
+
     { ngx_string("Location"),
                  ngx_http_upstream_process_header_line,
                  offsetof(ngx_http_upstream_headers_in_t, location),
diff -r 341e4303d25b -r 45362796f681 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h	Thu Jul 16 14:20:48 2015 +0300
+++ b/src/http/ngx_http_upstream.h	Mon Jul 27 16:28:24 2015 +0300
@@ -256,6 +256,7 @@
     ngx_table_elt_t                 *location;
     ngx_table_elt_t                 *accept_ranges;
     ngx_table_elt_t                 *www_authenticate;
+    ngx_table_elt_t                 *proxy_authenticate;
     ngx_table_elt_t                 *transfer_encoding;
     ngx_table_elt_t                 *vary;
 



More information about the nginx-devel mailing list