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:
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 from0.0
(lowest) to1.0
(highest). If omitted, the default value is1.0
.
Examples of valid syntax
Examples
Requesting Chunked Encoding
A client requests a resource and specifies that it only supports chunked
transfer encoding.
Client Request:
Server Response:
Requesting Multiple Encodings with Preferences
A client requests a resource and indicates that it prefers deflate
over gzip
but accepts both.
Client Request:
Server Response (if deflate
is supported):
Server Response (if deflate
is not supported but gzip
is):
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.