# Encoding your HTTP for fun and profit

DevFeed: [Encoding your HTTP for fun and profit](<https://devfeed.tech/articles/encoding-your-http-for-fun-and-profit-19070.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/http-encodings/>)

Author: HTTP Toolkit; Tim Perry

Published: 2021-06-10T14:00:00Z

Content type: article

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [HTTP](<https://devfeed.tech/topics/http.md>), [Compression](<https://devfeed.tech/topics/compression.md>), [Web app](<https://devfeed.tech/topics/webapp.md>), [JSON](<https://devfeed.tech/topics/json.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [base64](<https://devfeed.tech/tags/base64.md>), [compression](<https://devfeed.tech/tags/compression.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [encryption](<https://devfeed.tech/tags/encryption.md>), [gzip](<https://devfeed.tech/tags/gzip.md>), [http](<https://devfeed.tech/tags/http.md>), [json](<https://devfeed.tech/tags/json.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

HTTP content encoding wraps a request or response body; it is distinct from Content-Type, which describes the content after decoding. For example, gzip-encoded JSON uses Content-Encoding: gzip and Content-Type: application/json. Compression is the main use, reducing body size and potentially bandwidth and load time; content encoding can also describe encryption or compatibility formats such as base64. The excerpt distinguishes this from transfer-encoding, which operates hop by hop; it identifies chunked encoding as common for sending data without a known length and says it is largely separate from compression. Server or CDN defaults may be absent or may not suit every situation.

## Source excerpt

HTTP content encoding is an incredibly powerful tool that can save you huge amounts of bandwidth and make your web or mobile application faster, basically for free. Unfortunately, it's poorly understood by most developers. There's a lot of power here, but few people are aware of the options or what "content encoding" really means, so it's mostly left to be handled automatically (for better or worse) by your web server. In many cases that means no encoding at all. In some helpful cases (typically CDNs or static site PaaS hosts) a useful basic default will be provided, but those defaults are rarely the best choice for every situation. With just a tiny sprinkle of knowledge, you can enable this and speed up your web application, your API, and all your HTTP requests & responses in no time at all. What is content encoding? Content encoding is the wrapper around the meaningful body of an HTTP request or response. It is not the type of the content - that's something else entirely. This is a common mistake! For example, you might have a response that contains JSON data, encoded with gzip. In that case, you'd use HTTP headers like: Content-Encoding: gzip Content-Type: application/json This tells the HTTP client that it needs to unwrap the content using gzip, and then it's going find some JSON inside. That's the best way to think of it: if you receive a request or response with a content-encoding header, then you should undo that content encoding (e.g. un-gzip the body) and then you'll find content that matches the content-type header. The main use for this by a very long way is compression: there's a variety of different compression algorithms you can use to shrink your request and response bodies dramatically. You could also use it to describe a layer of encryption around the content though (for unusual environments where HTTPS isn't sufficient/possible) or to send content encoded in a format that's more easily compatible with other infrastructure (encoding it as base64 rat