# Response content-length header stripped when content-type is "text/html"

**URL:** <https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810>\
**Category:** General\
**Created:** [February 12, 2019, 9:59pm UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810 "2019-02-12T21:59:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Sbriscia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/ross_sbriscia/32/118_2.png) [@Ross\_Sbriscia](https://discuss.konghq.com/u/Ross_Sbriscia)\
**Post date:** [February 12, 2019, 9:59pm UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/1 "2019-02-12T21:59:16Z")

</div>

When examining `ngx.header.content_length` of a RESPONSE, we notice this field is `nil` ONLY when the response `content-type` is `text/html`.

In all cases, the `Content-Length` header is being explicitly set on the response. And `ngx.header.content_length` is accurate when the `Content-Type` is any of the following: `text/plain`, `application/json`, `application/xml`. Only for `text/html` is it `nil`.

So I’m thinking maybe something in Kong, ngx, openresty is stripping it? But only for this specific `content-type` value?

Any thoughts?

Edit: This is in Kong 1.0

---

<div class="post-metadata">

**Author:** ![jeremyjpj0916](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/jeremyjpj0916/32/1388_2.png) [@jeremyjpj0916](https://discuss.konghq.com/u/jeremyjpj0916)\
**Post date:** [February 13, 2019, 9:39am UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/2 "2019-02-13T09:39:03Z")

</div>

Sat and looked at this with Ross for a few hours today stumped as to why one of our plugins was seemingly acting bugged even while the high level logic looked fine:

> **[Optum/kong-response-size-limiting](https://github.com/Optum/kong-response-size-limiting)**
>
> Block responses with bodies greater than a specified size - Optum/kong-response-size-limiting

Of course text/html should never really be seen as an API response content-type, but still the fact either Kong/OpenResty/Nginx does not populate the content-length in the ngx response headers context in this scenario is weird because we echo it and verified its certainly set when hitting it directly.

---

<div class="post-metadata">

**Author:** ![kikito](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/kikito/32/15_2.png) [@kikito](https://discuss.konghq.com/u/kikito)\
**Post date:** [February 13, 2019, 5:18pm UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/3 "2019-02-13T17:18:50Z")

</div>

Hi,

I have created a Github issue to investigate this: [https://github.com/Kong/kong/issues/4306](https://github.com/Kong/kong/issues/4306)

---

<div class="post-metadata">

**Author:** ![jeremyjpj0916](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/jeremyjpj0916/32/1388_2.png) [@jeremyjpj0916](https://discuss.konghq.com/u/jeremyjpj0916)\
**Post date:** [February 20, 2019, 10:05pm UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/4 "2019-02-20T22:05:50Z")

</div>

This has been solved, bit of a false alarm here. Sorry folks I am just a bad coder 😆 . @Ross_Sbriscia we can close this question and mark as answered.

---

<div class="post-metadata">

**Author:** ![bungle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bungle/32/13_2.png) [@bungle](https://discuss.konghq.com/u/bungle)\
**Post date:** [February 21, 2019, 6:59pm UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/5 "2019-02-21T18:59:54Z")

</div>

Still somewhat puzzled why it happened in a first place. Would love to see all the request and response headers. Why the ngx.header[“Content-Length”] gets cleared? Does some other plugin do it? Is there some other things in response that makes it turn to chunked (is that what is happening?). But sure I am glad there was a workaround.

---

<div class="post-metadata">

**Author:** ![jeremyjpj0916](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/jeremyjpj0916/32/1388_2.png) [@jeremyjpj0916](https://discuss.konghq.com/u/jeremyjpj0916)\
**Post date:** [February 22, 2019, 5:51am UTC](https://discuss.konghq.com/t/response-content-length-header-stripped-when-content-type-is-text-html/2810/6 "2019-02-22T05:51:19Z")

</div>

Well Mr. Bungle it really was nothing out of the ordinary in the response headers that I recalled, nothing around chunked/encoding stuffs. No other plugins were on it that I know of for those calls. It was just dummy data in the http body and text/html as content-type that did it for us with content-length set to the byte size of dummy data. If I can get Ross to post the raw headers the full response had coming back from the echo webserver I will, but my guess is he won’t want to revisit this as I think he spent like 6-8 hours around this issue in total back when he was pulling his hair out wondering why either his test-suite(we wrote a plugin validation test suite recently to catch plugins breaking in functionality from version to version) or why the response-size-limiting plugin we had was wrong 😆 .

I was scratching my head thinking why the plugin was wrong then I remembered I had been using pure ngx stuff, then quickly changed it to use pdk at one point, saw mem leaks, tibo fixed mem leaks but during that time i hastily reverted back to pure ngx(and did so wrongly). So I think was all just my goof of choosing the wrong way to get that header, In the context of the header phase on the response, I suppose ngx.header[“Content-Length”] still should represent the request size eh? So maybe its interesting that the content-type on the response changing from say application/xml to text/html caused it to nil out was interesting but ultimately had nothing to do with what was our actual problem.
