HTTP Content Negotiation/Compression: Use Base64 with Accept-Encoding/Content-Encoding?
-
26-06-2021 - |
Question
I'm wondering if the following idea is working against the spirit and/or letter of HTTP Content Negotiation and HTTP Compression.
The Situation
The HTTP Client requests a resource:
HTTP GET /image.jpeg HTTP/1.1
Accept: image/jpeg
The HTTP Server returns this resource:
HTTP/1.1 200 OK
Content-Type: image/jpeg
The Idea
The Client thinks it's a good idea to request the resource encoded:
HTTP GET /image.jpeg HTTP/1.1
Accept: image/jpeg
Accept-Encoding: base64
The Server honors this request and returns the resource encoded:
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Encoding: base64
The Question
I'm not quite happy with this idea. HTTP Compression, for which the Accept-Encoding
and Content-Encoding
headers are used, is about compressing data, not about increasing its size as Base64 does.
Is the use of base64
as a value for these headers a violation of the spirit and/or letter of HTTP Content Negotiation and HTTP Content Compression?
Solution
RFC 2616 section 3.5 (emphasis mine):
Content codings are primarily used to allow a document to be compressed or otherwise usefully transformed without losing the identity of its underlying media type and without loss of information.
Your idea is perfectly in line with the “spirit and letter” of HTTP.