Utilo

GZ MIME Type – Free, Online, Private

application/gzip means the body is a gzip file. Content-Encoding: gzip means the body is a compressed representation of some other type.

What .gz is

A gzip file starts with the bytes 1F 8B. A method byte, flags, a timestamp, and a DEFLATE stream follow. The original filename may be stored in the header and may be absent. RFC 6713 registers application/gzip for this file. That is not the same header as Content-Encoding: gzip. Content-Encoding says the bytes on the wire are a compressed form of the Content-Type, and the client inflates them before it handles the type. application/gzip says the file the user wanted is itself a gzip archive, and the client should save or decompress it as a file. Mixing those up is the bug this page is about.

IANA registers application/gzip in RFC 6713. The media type is application/gzip. Extensions that use it on this page: .gz. A client compares the type, not the filename, once the response has arrived. The filename still matters on disk and in Content-Disposition, which is why a wrong extension and a wrong header are two different bugs.

What sends application/gzip

What sends application/gzip: Send application/gzip for a .gz download, including a .tar.gz you are not unpacking. A tarball compressed with gzip is often application/gzip with a filename that ends in .tar.gz, and some servers use application/gzip for .tgz as well. You can be more specific in the filename even when the type stays application/gzip. Do not send application/gzip for a CSS file you compressed on the fly. That response is text/css with Content-Encoding: gzip. Do not add a charset. The member inside may be text. The gzip container is binary. The file on disk is still .gz. Once the response exists, a client trusts application/gzip, not the filename. If you offer both a .tar and a .tar.gz, they are two URLs. The tar URL is the tar type. The gz URL is application/gzip. Redirecting one to the other without changing the type caches a gzip body under a tar URL.

Content-Type for .gz

Send application/gzip and do not add a charset parameter. The body is binary. A charset tells a text decoder to reinterpret bytes that are not text, which corrupts a download and does not help a browser sniff the format.

Content-TypeContent-Type: application/gzip

nginx, Apache, and Express

These snippets map .gz to application/gzip. nginx reads the types block when it picks a type from the URL's extension. A location that sets default_type, or an application that sets the header itself, overrides that map. Apache AddType applies in the directory context where you put it. The Express static example writes the header for files ending in .gz so a stale mime database in the framework cannot disagree with the type on this page.

nginx# /etc/nginx/mime.types, inside the types { } block
application/gzip            gz;
ApacheAddType application/gzip .gz
Expressimport express from "express";

const app = express();
app.use(express.static("public", {
  setHeaders(res, filePath) {
    if (filePath.endsWith(".gz")) {
      res.setHeader("Content-Type", "application/gzip");
    }
  },
}));

Pitfalls for application/gzip

Pitfalls that show up for application/gzip, and not for a neighboring type with a similar extension: A CDN that gzips every response and also leaves a .gz file's type as application/gzip will sometimes compress twice or strip one layer and store the wrong bytes. Decide which layer you mean. Another trap is a client that auto-inflates any body starting with 1F 8B and then finds a tar archive it did not expect, because the URL ended in .gz and the member was a .tar. Name the file .tar.gz when the member is a tarball. Another is a gzip stream with multiple members. Some decompressors stop after the first. Another is a corrupt CRC at the end, which only appears after you inflate. The type can be correct on a truncated body.

  • Content-Encoding: gzip is not application/gzip. One is a transfer coding of another type. The other is the file.
  • application/x-gzip is unofficial. RFC 6713's type is application/gzip.
  • .tgz is a tar archive that was gzipped. The type is still application/gzip unless you have a more specific contract.
  • Do not send a charset on the gzip container.

Frequently asked questions

How is this different from Content-Encoding?

application/gzip is a gzip file the client should keep as a file. Content-Encoding: gzip is a compressed HTTP representation of whatever Content-Type names.

What is the magic?

The two bytes 1F 8B.

What type is a .tar.gz?

application/gzip. The tar member is inside. The tar type applies after decompression, not on the wire, unless you decompressed it on the server.

Is application/x-gzip still used?

Old maps send it. The registered type is application/gzip.