nginx conditional Accept header

Posted by manu_v on Server Fault See other posts from Server Fault or by manu_v
Published on 2012-11-30T09:45:25Z Indexed on 2012/11/30 11:08 UTC
Read the original article Hit count: 252

Filed under:
|
|

Some mobile devices send the following incorrect requests to our servers :

GET / HTTP/1.0
Accept:
User-Agent : xxx

The empty Accept header causes our Ruby on Rails server to throw back a 500 error.

In Apache, the following directive allows us to rewrite the header before sending it to the application RoR server in order to cope with the broken devices :

    RequestHeader edit Accept ^$ "*/*" early

We're currently setting up nginx, but achieving the same work-around is proving difficult. We are able to set :

  proxy_set_header Accept */*;

However, this seems to have to be done inconditionally. Whenever trying to do :

if ($http_accept !~ ".") {
  proxy_set_header Accept */*;
}

It complains with the message :

"proxy_set_header" directive is not allowed here

So, using nginx, how can we set the HTTP Accept header to */* when it is empty before sending the request to the application server ?

© Server Fault or respective owner

Related posts about nginx

Related posts about ruby-on-rails