# Gzip not compressing response body with status code other than 200, 403, 404

**URL:** <https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818>\
**Category:** NGINX\
**Created:** [June 3, 2011, 12:17pm UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818 "2011-06-03T12:17:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 3, 2011, 12:17pm UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818/1 "2011-06-03T12:17:12Z")

</div>

Hello,

I have a WebDAV application setup with nginx in front of application  
server  
for reverse proxying. My application returns 207 as status code and I  
found  
that nginx does not compress response body with gzip other than 200, 403  
and  
404 status. Is there any reason behind this?

Regards,  
Tony

---

<div class="post-metadata">

**Author:** ![Tony\_Tsang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@Tony\_Tsang](https://www.ruby-forum.com/u/Tony_Tsang)\
**Post date:** [August 27, 2012, 1:59pm UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818/2 "2012-08-27T13:59:49Z")

</div>

I met same problem while try to gzip response with other status code.  
Any  
update for this issue?

Posted at Nginx Forum:

> **[Re: Gzip not compressing response body with status code other than 200, 403, 404](https://forum.nginx.org/read.php?2,203569,230115#msg-230115)**
>
> Hello, I have a WebDAV application setup with nginx in front of application server for reverse proxying. My application returns 207 as status code and I found that nginx does not compress response body with gzip other than 200, 403 and 404 status. Is...

---

<div class="post-metadata">

**Author:** ![Tony\_Tsang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@Tony\_Tsang](https://www.ruby-forum.com/u/Tony_Tsang)\
**Post date:** [September 1, 2012, 2:53am UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818/3 "2012-09-01T02:53:43Z")

</div>

Hello!

On Sat, Aug 25, 2012 at 02:32:02AM -0400, soniclee wrote:

> I met same problem while try to gzip response with other status code. Any  
> update for this issue?

In some cases it’s just not possible to compress  
response, e.g. you can’t compress 206 as it doesn’t contain full  
entity body. Or you can’t compress 304 as it has no entity at  
all.

In many cases it’s unwise/unsafe to compress responses with some  
status codes. I.e. you probably don’t want to compress 400 (Bad  
Request) response even if client claimed gzip support before it  
did some syntax error in the request - as you already know client  
did something wrong, and it’s better to return easy to understand  
response. Or e.g. if you try to return 500 (Internal Server  
Error) due to memory allocation error - you probably don’t want to  
allocate memory for gzip.

Due to the above reasons gzip compression is done only for certain  
common and safe response codes. And from the above explanation it  
should be more or less obvious that it just can’t be enabled for  
all status codes.

If you think gzip compression should be enabled for some specific  
status code - please provide your suggestions with reasoning.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Tony\_Tsang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@Tony\_Tsang](https://www.ruby-forum.com/u/Tony_Tsang)\
**Post date:** [March 3, 2013, 4:08pm UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818/4 "2013-03-03T16:08:45Z")

</div>

Hello Maxim,

On Sat, 01 September 2012 Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In many cases it’s unwise/unsafe to compress responses with some  
> should be more or less obvious that it just can’t be enabled for  
> all status codes.
> 
> If you think gzip compression should be enabled for some specific  
> status code - please provide your suggestions with reasoning.

One status code that should allow compression is 410 “Gone”, it  
is mostly equivalent to 404 just stronger. (patch attached)

Probably most 5xx error pages generated by an upstream should  
also be compressed if the request as seen by nginx is valid.  
(e.g. a 503 or 500 error returned by upstream, especially when they  
are rather large)

Bruno

---

<div class="post-metadata">

**Author:** ![Tony\_Tsang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@Tony\_Tsang](https://www.ruby-forum.com/u/Tony_Tsang)\
**Post date:** [March 4, 2013, 1:28pm UTC](https://www.ruby-forum.com/t/gzip-not-compressing-response-body-with-status-code-other-than-200-403-404/207818/5 "2013-03-04T13:28:29Z")

</div>

Hello!

On Sun, Mar 03, 2013 at 04:07:50PM +0100, Bruno Prémont wrote:

> > entity body. Or you can’t compress 304 as it has no entity at
> > 
> > Due to the above reasons gzip compression is done only for certain  
> > common and safe response codes. And from the above explanation it  
> > should be more or less obvious that it just can’t be enabled for  
> > all status codes.
> > 
> > If you think gzip compression should be enabled for some specific  
> > status code - please provide your suggestions with reasoning.
> 
> One status code that should allow compression is 410 “Gone”, it  
> is mostly equivalent to 404 just stronger. (patch attached)

Any specific reason to? 410 is rarely used at all, and I don’t  
think we should treat it as a common response code which is safe to  
compress.

> Probably most 5xx error pages generated by an upstream should  
> also be compressed if the request as seen by nginx is valid.  
> (e.g. a 503 or 500 error returned by upstream, especially when they  
> are rather large)

With errors, especially 5xx, you never know what actually went  
wrong, and what will happen due to compression applied. It’s  
always safer to respond with what we get from an upstream with  
minimal modifications.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
