Why are PNG and TIFF formats treated differently than JPG and GIF by a webserver?

3

  • I observed that my web-browser kept download PNG and TIFF images, while happily displayed JPG and GIF when I clicked on a link to that image. Ex. http://somesite.com/image.<format>

  • On closer inspection of the HTTP response headers, I observed that the difference in the Content-Disposition and Content-Type headers was causing this behavior.

Anyone know why these are treated differently?


PNG:

HTTP/1.1 200 OK
Date: Fri, 16 Jan 2015 01:33:05 GMT
Server: Apache/2.2.21 (CentOS)
Content-Disposition: attachment;filename*=UTF-8''PNG.png
Content-Type: application/octet-stream

JPG:

HTTP/1.1 200 OK
Date: Fri, 16 Jan 2015 01:34:43 GMT
Server: Apache/2.2.21 (CentOS)
Content-Disposition: inline;filename*=UTF-8''JPG.jpg
Content-Type: image/jpeg

GIF:

HTTP/1.1 200 OK
Date: Fri, 16 Jan 2015 01:31:28 GMT
Server: Apache/2.2.21 (CentOS)
Content-Disposition: inline;filename="GIF.gif"
Content-Type: image/gif

Kent Pawar

Posted 2015-01-16T04:19:31.043

Reputation: 562

Your browser decides whether it will download the file or just display it in place. Which browser are you using? – user3767013 – 2015-01-16T07:57:26.367

@user3767013 - Tested on IE and Chrome. I believe the behavior is almost universal. Note that the images were not embedded into the HTML in <img> tags but were links to the file. – Kent Pawar – 2015-01-17T09:53:10.370

Answers

3

The web server that is serving the files is not configured correctly to serve those image types. The generic, "unknown" Content Type is application/octet-stream. The browser uses the Content-Type header to decide how to handle the file,and since it doesn't have anything to handle it, it just downloads the file.

Most Apache installations have a mime.types file in their configuration that handles the file extension to content type mapping.

The server is also setting the Content-Disposition header to attachment which will also cause the browser to download the file instead of display it inline.

heavyd

Posted 2015-01-16T04:19:31.043

Reputation: 54 755