# Cannot remove Content Length header

**URL:** <https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177>\
**Category:** NGINX\
**Created:** [September 24, 2011, 1:44pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177 "2011-09-24T13:44:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 24, 2011, 1:44pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/1 "2011-09-24T13:44:12Z")

</div>

Hello,

I’m using Nginx as a front end to my node.js application, nginx proxying  
https request to my app.  
When the browser gets the response back, instead of pure json  
({“error”:“query error”,“message”:“Parameter(s) missing:  
user,password”}), I  
receive something like:

47  
{“error”:“query error”,“message”:“Parameter(s) missing: user,password”}  
0

I use ‘more\_clear\_headers’ module but do not have any luck.

This is the config I use:

server {  
listen 443;  
server\_name [my.server.com](http://my.server.com);  
ssl on;  
ssl\_certificate certificate.pem;  
ssl\_certificate\_key privatekey.pem;

```
keepalive_timeout 70;

location / {
  more_clear_headers 'Content-Length'; # Does not work as I would

```

expect  
proxy\_pass [https://localhost:8443](https://localhost:8443);  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_buffering off;  
proxy\_buffers 8 8k;  
}  
}

Would you have any idea ?  
Thanks a lot for your help,

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 1:50pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/2 "2011-09-24T13:50:22Z")

</div>

How are you testing it?  
That looks like results I saw using telnet but those numbers do not  
appear with a http client such as curl

On 24 Sep 2011, at 12:43, “Luc J.”  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

Hello,

I’m using Nginx as a front end to my node.js application, nginx proxying  
https request to my app.  
When the browser gets the response back, instead of pure json  
({“error”:“query error”,“message”:“Parameter(s) missing:  
user,password”}), I receive something like:

47  
{“error”:“query error”,“message”:“Parameter(s) missing: user,password”}  
0

I use ‘more\_clear\_headers’ module but do not have any luck.

This is the config I use:

server {  
listen 443;  
server\_name [http://my.server.com](http://my.server.com)  
[my.server.com](http://my.server.com)[http://my.server.com](http://my.server.com);  
ssl on;  
ssl\_certificate certificate.pem;  
ssl\_certificate\_key privatekey.pem;

```
keepalive_timeout 70;

location / {
  more_clear_headers 'Content-Length'; # Does not work as I would 

```

expect  
proxy\_pass [https://localhost:8443](https://localhost:8443) [https://localhost:8443](https://localhost:8443);  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_buffering off;  
proxy\_buffers 8 8k;  
}  
}

Would you have any idea ?  
Thanks a lot for your help,

–  
Luc

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 2:05pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/3 "2011-09-24T14:05:46Z")

</div>

Hello!

On Sat, Sep 24, 2011 at 01:43:12PM +0200, Luc J. wrote:

> 0  
> This is chunked encoding, likely sent by your backend in violation  
> of HTTP specification.

Right now there are two options available:

1. Fix your backend.

2. Upgrade to nginx 1.1.4, it has code needed to talk to such  
broken backends.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 2:59pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/4 "2011-09-24T14:59:28Z")

</div>

Hello,

thanks for your answers.  
Maxim, what would you recommend to fix the backend ? I do not really see  
where could be the violation in fact.

–  
Luc

Le Sep 24, 2011 14:05, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a crit :

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 3:07pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/5 "2011-09-24T15:07:31Z")

</div>

Hello,

I’m testing it from a browser and with curl as well and I got the same.  
When I bypass nginx the response is correct. When I request from nginx,  
the lenght is added at the beginning and 0 at the end of the json I  
would expect.

–  
Luc

Le Sep 24, 2011 13:49, Richard K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a  
crit :

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 4:55pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/6 "2011-09-24T16:55:26Z")

</div>

Hello!

On Sat, Sep 24, 2011 at 02:58:59PM +0200, Luc J. wrote:

> Hello,
> 
> thanks for your answers.  
> Maxim, what would you recommend to fix the backend ? I do not really see where  
> could be the violation in fact.

Backend MUST NOT (as per RFC 2616) return chunked to HTTP/1.0  
clients, while nginx uses HTTP/1.0 to talk to backends.

See RFC 2616, “3.6 Transfer Codings”  
[http://tools.ietf.org/html/rfc2616#section-3.6](http://tools.ietf.org/html/rfc2616#section-3.6)

… A server MUST NOT send transfer-codings to an HTTP/1.0  
client.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 24, 2011, 7:24pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/7 "2011-09-24T19:24:55Z")

</div>

Does it mean something (like a parameter or something) needs to be  
modified on my node.js application ? Do I need to send additionnal stuff  
? I did not really get the “chunked” part.

–  
Luc

Le Sep 24, 2011 16:54, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a crit :

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 25, 2011, 6:07pm UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/8 "2011-09-25T18:07:07Z")

</div>

Thanks, I corrected this on back-end side (adding a content-length).  
Luc

2011/9/24 Luc J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Luc\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Luc\_J](https://www.ruby-forum.com/u/Luc_J)\
**Post date:** [September 26, 2011, 10:16am UTC](https://www.ruby-forum.com/t/cannot-remove-content-length-header/212177/9 "2011-09-26T10:16:00Z")

</div>

Luc J. wrote in post #1023663:

> Thanks, I corrected this on back-end side (adding a content-length).  
> Luc
> 
> 2011/9/24 Luc J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Maxim,

We are facing issues with certain phones which post data with chunked  
headers and no content length. These clients get error as 411.

i have tried this w/ apache it works.

Have we fixed this in any of current stable release we have any patch  
for it to work.

Issue is similar to the one discussed in this link:  
[http://www.ruby-forum.com/topic/162976](http://www.ruby-forum.com/topic/162976)

Regards,  
Sandesh K
