nginx + rails + PUT + curl = 411 Length Required

One of my RESTful resources supports a PUT in order to get the next item in the queue and dequeue it. It is a PUT as opposed to a GET because it changes the state of the queue, and we all know that GETs should be idempotent.

In order to test this, I was using the following sort of curl command:

$ curl -i -X PUT 'http://localhost:3000/resource_name.xml;dequeue'

Worked fine on localhost. However, when I setup this up in staging going through nginx and over https, I ran the same command and got an unexpected result:

411 Length Required

So, I knew it was nginx that was giving me grief as opposed to mongrel and/or Rails suddenly changing its mind. I found the following note on the subject and changed the command to include setting the Content-Length header to zero, resulting in the following successful form of the curl command:

$ curl -i -X PUT -H 'Content-Length: 0' 'https://staging/resource_name.xml;dequeue'

Leave a Reply