Skip to content

TE (Transfer Encoding)

Description

The TE (Transfer Encoding) request header is used by HTTP clients to indicate what transfer encodings they are willing to accept in the response, aside from the standard chunked transfer encoding. This header is primarily used in HTTP/1.1 to facilitate encoding negotiations between the client and server.

Typically, the TE header is used when a client wants to receive an encoded response using a specific encoding method. However, in modern applications, chunked is the only commonly supported value, as other transfer encodings have been deprecated or are rarely implemented.

If a client sends a TE header, the server will determine if it supports the requested encoding and respond accordingly. If the server does not support the specified encoding, it may ignore the header or return an error.

Syntax

The TE header follows this syntax:

TE: <encoding>[;q=<quality>]

Where:

  • <encoding> specifies the transfer encoding the client supports (e.g., chunked, gzip, compress, deflate).
  • q=<quality> is an optional parameter indicating the relative preference for different encodings, with values ranging from 0.0 (lowest) to 1.0 (highest). If omitted, the default value is 1.0.

Examples of valid syntax

TE: chunked
TE: compress, gzip;q=0.5
TE: deflate;q=0.8, gzip;q=0.6

Examples

Requesting Chunked Encoding

A client requests a resource and specifies that it only supports chunked transfer encoding.

Client Request:

GET /data HTTP/1.1
Host: example.com
TE: chunked

Server Response:

HTTP/1.1 200 OK
Transfer-Encoding: chunked

[Chunked response body]

Requesting Multiple Encodings with Preferences

A client requests a resource and indicates that it prefers deflate over gzip but accepts both.

Client Request:

GET /data HTTP/1.1
Host: example.com
TE: deflate;q=0.8, gzip;q=0.6

Server Response (if deflate is supported):

HTTP/1.1 200 OK
Transfer-Encoding: deflate

[Deflate-encoded response body]

Server Response (if deflate is not supported but gzip is):

HTTP/1.1 200 OK
Transfer-Encoding: gzip

[Gzip-encoded response body]

Summary

The TE request header is used by HTTP clients to specify which transfer encodings they support. While historically used for multiple encoding types, modern implementations primarily support chunked encoding. If a server supports the requested encoding, it will use it in the response; otherwise, it may ignore the header. Understanding the TE header is useful in optimizing data transfer and ensuring compatibility between clients and servers.