About Gzip file files
Registered in RFC 6713; application/x-gzip is the older name. Don’t confuse the content type with Content-Encoding: gzip: if a server sends a .tar.gz download with Content-Encoding: gzip, the browser decompresses it on the fly and saves a plain .tar under a .tar.gz name.
Other types seen for these files:
application/x-gzip
. Accept them when reading uploads, but send application/gzip yourself.
File signature
GZ files start with 1F 8B. The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .gz with the right Content-Type
Content-Type: application/gzip
application/gzip gz tgz;
AddType application/gzip .gz .tgz
@gz path *.gz *.tgz
header @gz Content-Type "application/gzip"
curl -sI https://example.com/file.gz | grep -i '^content-type'
# Content-Type: application/gzip
Set the type in code
res.set('Content-Type', 'application/gzip');
// Or make the browser download it:
res.attachment('file.gz');
import mimetypes
mimetypes.add_type('application/gzip', '.gz') # if your system doesn't know it
mimetypes.guess_type('file.tar.gz') # ('application/x-tar', 'gzip')
mime.AddExtensionType(".gz", "application/gzip")
w.Header().Set("Content-Type", "application/gzip")
Accept .gz uploads
<input type="file" accept=".gz,.tgz,application/gzip">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.tar (
application/x-tar): Tar archive -
.zip (
application/zip): ZIP archive -
.7z (
application/x-7z-compressed): 7-Zip archive
More archives
.rar . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .gz files?
application/gzip. You may also see application/x-gzip, which is older or unofficial; send application/gzip. The full header is "Content-Type: application/gzip".
Why does my server send the wrong Content-Type for .gz?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .gz is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is GZ?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. GZ files start with 1F 8B. The MIME type lookup on this site reads them for you when you drop a file on it.