Content-Type vs Content-Encoding with gzip response

3,608 views
Skip to first unread message

Bill Tschumy

unread,
Nov 24, 2009, 5:19:19 PM11/24/09
to ASIHTTPRequest
The server I'm making a request from is returning a gzipped response.
However ASIHttpRequest is not unzipping it for me as it should.
Looking at the response headers I see the server returns

key: Content-Type, value: application/gzip

However, ASIHttpRequest is looking for the Content-Encoding header in
order to determine if it should unzip the data. Since this header is
not set, the data is return raw.

Who is at fault here? Should the server be setting the Content-
Encoding header or should ASIHttpRequest also be looking at the
Content-Type to see if it is gzipped?

I have modified the isResponseCompressed method to check both headers
and that seems to make it work in my case. Will it cause other
problems down the road?

Ben Copsey

unread,
Nov 25, 2009, 5:30:20 AM11/25/09
to asihttp...@googlegroups.com
Hi Bill

> The server I'm making a request from is returning a gzipped response.
> However ASIHttpRequest is not unzipping it for me as it should.
> Looking at the response headers I see the server returns
>
> key: Content-Type, value: application/gzip
>
> However, ASIHttpRequest is looking for the Content-Encoding header in
> order to determine if it should unzip the data. Since this header is
> not set, the data is return raw.
>
> Who is at fault here? Should the server be setting the Content-
> Encoding header or should ASIHttpRequest also be looking at the
> Content-Type to see if it is gzipped?

I don't think either is necessarily at fault. As far as I understand, the Content-Type header tells clients about the content of the resource, the Content-Encoding tells them about the format the server is using to transmit it.

If I want to download a .gz file, I would expect the server to return an application/gzip or application/x-gzip Content-Type. What I end up with should be a gzip file.

If I want to download a text file, and the server decides to gzip the content to reduce the size of the data transmitted, I would expect it to send me a Content-Encoding: gzip header. What I end up with should be a text file, uncompressed, as the file's content was only gzipped for transmission.

> I have modified the isResponseCompressed method to check both headers
> and that seems to make it work in my case. Will it cause other
> problems down the road?

I can't imagine that would cause any problems, unless in future you want to download gzip files and leave them compressed.

Best,

Ben
Reply all
Reply to author
Forward
0 new messages