8

As per the RFC and MDN docs, ETag value is required to be enclosed in double quotes "<Value>". When I make a request using CURL with the Accept-Encoding header as gzip, deflate, br, I do not receive the ETag in the response headers if ETag is not enclosed around double-quotes.

I am curious about why the ETag specification requires them to be enclosed in double-quotes?

1
  • Pedantically speaking: the value is not enclosed in quotes - the quotes are part of the value. Mar 8, 2021 at 17:48

1 Answer 1

6

I don't know of any source that explicitly says why the double quotes are required.

What we can say, though, is that the value of the ETag header includes metadata in addition to the entity tag itself. Specifically, when the value starts with the string W/ it means that the following entity tag should be considered weak.

So there has to be some way to distinguish the value from the metadata. There are many possible solutions. They could have left off the quotes, but then there would have to be a magic character sequence for the metadata, and probably some escaping mechanism for when the entity tag happened to include those characters.

The approach taken in the standard is simple, readable, uses familiar delimiting characters, and is fast to parse. Indeed, we have a clue that the last part is important since there are no escape sequences (meaning that " is not itself allowed in the internal part of the tag).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.