10

Is there any way to know if the message body of an HTTP response is encoded with Base64?

I learnt that content-transfer-encoding is not part of HTTP header.

So, which HTTP header indicates that the content is encoded with Base64? I think Content-encoding is only used for compressions.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Anant
  • 109
  • 1
  • 2
  • 5
  • I think this thread is similar to what your looking for http://security.stackexchange.com/questions/3989/how-to-determine-what-type-of-encoding-encryption-has-been-used – e1on Nov 07 '12 at 08:41
  • 1
    why do you want to encode in base64 anyway? – Julian Reschke Nov 07 '12 at 10:33
  • I am the proxy and want to check for the traffic. I whole intention is see HTTP packet, check whether the content is encoded or not. – Anant Nov 07 '12 at 11:27
  • Anant: so the answer is: there is nothing specific to base64 in HTTP – Julian Reschke Nov 07 '12 at 13:06
  • More specifically: a base64 content-coding parameter is [not registered](http://www.iana.org/assignments/http-parameters/http-parameters.xml); you should not have to expect nor implement it. If no Content-Encoding-header is present, you may assume the data in the message body is transferred as-is. – CodeCaster Nov 07 '12 at 13:24

1 Answers1

9

As far as I understand, an HTTP body may not be encoded in Base64:

HTTP does not use the Content-Transfer-Encoding (CTE) field of RFC 2045. Proxies and gateways from MIME-compliant protocols to HTTP MUST remove any non-identity CTE ("quoted-printable" or "base64") encoding prior to delivering the response message to an HTTP client.

Identity being:

The default (identity) encoding; the use of no transformation whatsoever.

Of course you're allowed to transport Base64-encoded data using HTTP, but that should be something both parties (client and server) agree on, and there doesn't seem to be a header to describe this behavior.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Is it same with older HTTP versions? – Anant Nov 07 '12 at 11:15
  • 1
    Anant: yes, there never was base64 in HTTP – Julian Reschke Nov 07 '12 at 13:05
  • @Anant you say in a comment under your question that you're implementing an HTTP proxy. If you're doing so, I'd figure you'd know your way into and around the HTTP and related RFC's. The same text is present in the HTTP/1.0 RFC as well as the HTTP/1.1 RFC. – CodeCaster Nov 07 '12 at 13:47
  • I've actually seen YouTube transmit data as Base64, when I wrote a comment with Firefox's network debugger open and looked at the answer contents which looked like JSON but flipping the "Raw" switch made it appear in Base64, so how did the browser know that was JSON? Note: I couldn't find any header that told me that so either the debugger is good at guessing or there were some other shenanigans going on in the background. – Lampe2020 Apr 27 '23 at 06:21