🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Transfer Encoding

HTTP Header

The HTTP Transfer-Encoding request and response header specifies the form of encoding used to transfer messages between nodes on the network.

Transfer-Encoding is a hop-by-hop header, meaning it is applied to a message between two nodes and not to the resource itself.
Each segment of a multi-node connection can use different Transfer-Encoding values.
If you want to compress data over the entire connection, use the end-to-end Content-Encoding header instead.

When present in a response to a HEAD request that has no body, it indicates the value that would have been applied to the corresponding GET message.

Note:
HTTP/2 disallows all uses of the Transfer-Encoding header other than the HTTP/2 specific value "trailers".
HTTP/2 and later versions provide more efficient mechanisms for data streaming than chunked transfer.
Using the Transfer-Encoding header in HTTP/2 may result in a specific protocol error.

Header type Request header, Response header, Content header
Forbidden request headerYes

Syntax

Transfer-Encoding: chunked
Transfer-Encoding: compress
Transfer-Encoding: deflate
Transfer-Encoding: gzip

Several values can be listed, separated by a comma
Transfer-Encoding: gzip, chunked

Directives

These directives specify how data is transmitted over an HTTP connection, allowing for efficient data streaming and compression techniques to optimize web communication.

Data can be sent in chunks, which enables streaming of content of unknown size. This approach helps keep connections open and signals to the recipient when the entire message has been transmitted. In chunked transfer, the `Content-Length` header is omitted, and each chunk begins with a hexadecimal size, followed by the chunk data, and ends with a carriage return and line feed. The process terminates with a zero-length chunk.

Several content-encoding formats are used to compress data, reducing bandwidth usage and improving transfer times:

compress: Implements the Lempel-Ziv-Welch (LZW) algorithm, originally used by the UNIX compress program. Although it is rarely supported today due to patent issues, it serves as an important historical format.

deflate: Utilizes the zlib structure as defined in RFC 1950, with the deflate compression algorithm from RFC 1951. This method is widely supported and commonly used.

gzip: Uses the LZ77 algorithm combined with a 32-bit CRC for integrity checking. It originated from the UNIX gzip utility and is recommended by the HTTP/1.1 standard. Servers often recognize the alias `x-gzip` for compatibility.

Example

Response with chunked encoding

Chunked encoding is particularly useful when large amounts of data are sent to the client, and the overall size of the response might not be known until the entire request has been processed. This is common when generating large HTML tables from database queries or transmitting sizable images. A chunked response is formatted as follows:

HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked

How to Modify Header using Requestly

Requestly is a versatile Chrome extension that lets you modify HTTP headers, including the Transfer-Encoding header. Modifying this header can help you test how your server and client handle different types of data transfer encoding during development or troubleshooting. Steps to Modify the Transfer-Encoding Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter Transfer-Encoding.
    • In the “Header Value” field, enter the desired encoding (e.g., chunked).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. Save the rule.

Once configured, Requestly will inject or modify the Transfer-Encoding header in all matching requests, helping you simulate and test how your application deals with different transfer encoding methods.