x-accel-redirect enables caching for POST requests

Maxim Dounin mdounin at mdounin.ru
Thu Dec 24 18:24:04 UTC 2015


Hello!

On Thu, Dec 24, 2015 at 12:16:43AM +0300, Руслан Закиров wrote:

> On Wed, Dec 23, 2015 at 7:19 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> > On Wed, Dec 23, 2015 at 07:10:43PM +0300, Руслан Закиров wrote:
> >
> > > On Wed, Dec 23, 2015 at 6:49 PM, Maxim Dounin <mdounin at mdounin.ru>
> > wrote:
> > >
> > > > X-Accel-Redirect changes a request from POST to GET.
> > > >
> > >
> > > No, it doesn't. Getting request method POST on the backend and even form
> > > data is intact.
> >
> > It does,
> > http://hg.nginx.org/nginx/file/tip/src/http/ngx_http_upstream.c#l2501:
> >
> >             if (r->method != NGX_HTTP_HEAD) {
> >                 r->method = NGX_HTTP_GET;
> >             }
> >
> > Though it looks like it only does so for nginx itself, and this
> > indeed looks like a bug.  The code should be similar to one in
> >
> 
> Would you create an issue for this in tracker or do I need to so it doesn't
> disappear in archives?

No real need to open tickets.  I've submitted a patch for an 
internal review here.  Just in case, patch below.


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1450981046 -10800
#      Thu Dec 24 21:17:26 2015 +0300
# Node ID 10e233c763566b8466f6e302511094866a14e77a
# Parent  78b4e10b4367b31367aad3c83c9c3acdd42397c4
Upstream: fixed changing method on X-Accel-Redirect.

Previously, only r->method was changed, resulting in handling of a request
as GET within nginx itself, but not in requests to proxied servers.

See http://mailman.nginx.org/pipermail/nginx/2015-December/049518.html.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2499,6 +2499,7 @@ ngx_http_upstream_process_headers(ngx_ht
 
             if (r->method != NGX_HTTP_HEAD) {
                 r->method = NGX_HTTP_GET;
+                r->method_name = ngx_http_core_get_method;
             }
 
             ngx_http_internal_redirect(r, &uri, &args);


-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list