# Change HTTP method of Sub request

**URL:** <https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383>\
**Category:** NGINX\
**Created:** [March 19, 2010, 2:25am UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383 "2010-03-19T02:25:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 2:25am UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/1 "2010-03-19T02:25:00Z")

</div>

I have a Rails app that receives a POST and I would like to  
X-Accel-Redirect a file back to the client, but the fileserver is  
receiving a POST. Can I rewrite the HTTP method internally? I cannot  
find the documentation on this.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 8:03am UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/2 "2010-03-19T08:03:18Z")

</div>

On Fri, Mar 19, 2010 at 9:24 AM, W. Andrew Loe III  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a Rails app that receives a POST and I would like to  
> X-Accel-Redirect a file back to the client, but the fileserver is  
> receiving a POST. Can I rewrite the HTTP method internally? I cannot  
> find the documentation on this.

How about this?

```
location /proxy {
      set_unescape_uri $body $arg_body;
      echo_subrequest_async POST /fileserver -b $body
 }

```

Then X-Accel-Redirect to /proxy?body=xxxx where xxxx is the content  
body that you have read from within your PHP script.

Good luck 🙂  
-agentzh

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 8:05am UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/3 "2010-03-19T08:05:03Z")

</div>

On Fri, Mar 19, 2010 at 3:02 PM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> location /proxy {  
> set\_unescape\_uri $body $arg\_body;  
> echo\_subrequest\_async POST /fileserver -b $body  
> }

Forgot to mention that set\_unescape\_uri is provided by the  
ngx\_set\_misc module below:

```
http://github.com/agentzh/set-misc-nginx-module

```

and echo\_subrequest\_async is provided by the ngx\_echo module:

```
http://github.com/agentzh/echo-nginx-module

```

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 8:33am UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/4 "2010-03-19T08:33:44Z")

</div>

Hello!

On Thu, Mar 18, 2010 at 06:24:30PM -0700, W. Andrew Loe III wrote:

> I have a Rails app that receives a POST and I would like to  
> X-Accel-Redirect a file back to the client, but the fileserver is  
> receiving a POST. Can I rewrite the HTTP method internally? I cannot  
> find the documentation on this.

```
location /storage/ {
    proxy_pass http://storage-backend...;
    proxy_pass_method GET;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
}

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 6:03pm UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/5 "2010-03-19T18:03:21Z")

</div>

proxy\_pass\_method does not exist in the 0.7 or 0.8 branches. There is  
proxy\_method but I believe it simply allows more than the standard 4  
verbs to be proxied  
([Module ngx\_http\_proxy\_module](http://wiki.nginx.org/NginxHttpProxyModule#proxy_method)).

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 6:29pm UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/6 "2010-03-19T18:29:07Z")

</div>

Hello!

On Fri, Mar 19, 2010 at 10:02:31AM -0700, W. Andrew Loe III wrote:

> proxy\_pass\_method does not exist in the 0.7 or 0.8 branches. There is

Yes, I was too lazy to recheck exact name.

> proxy\_method but I believe it simply allows more than the standard 4  
> verbs to be proxied  
> ([http://wiki.nginx.org/NginxHttpProxyModule#proxy\_method](http://wiki.nginx.org/NginxHttpProxyModule#proxy_method)).

No, it sets method to be used in request to backend server.

Maxim D.

p.s. Please do not top-post. Thank you.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 7:53pm UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/7 "2010-03-19T19:53:24Z")

</div>

Hello!

On Fri, Mar 19, 2010 at 10:40:56AM -0700, W. Andrew Loe III wrote:

> Thank you, it works as you suggest, the documentation could use some  
> clarification!

Feel free to fix it, it’s wiki.

Maxim D.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [March 19, 2010, 6:41pm UTC](https://www.ruby-forum.com/t/change-http-method-of-sub-request/185383/8 "2010-03-19T18:41:24Z")

</div>

Thank you, it works as you suggest, the documentation could use some  
clarification!
