Search code examples
httpheaderrssetag

How to parse an ETag for use inside If-None-Match header


I have tried obtaining an ETag from various urls (RSS feeds), and obatained a different format for each one

W/"2c34-Lgd4oF7wqtfEvHc5kEphPr/7eaY"

W/"159a-VcHeTnlFfRm4lQABXPoMZNXbNSM"

o0Vn/cflaoT/ZhtK8pK+HPNXGAE (No quotes)

"80238bdb1dced51:0" (Quotes included)

kPn9GRCk70fI0HGuT3Yop7WU6DU (No quotes)

Can I use them all in an If-None-Match header the same way they were provided, do I need to add/remove quotes or maybe remove the W/


Solution

  • The syntax for ETag and If-None-Match is defined in RFC 7232.

    You'll see that the two headers use the same entity-tag reference; that is, the complete value for ETag (including quotes and W/) should be used in If-None-Match.

    Now, the two responses that don't include the quotes are not syntactically valid. That said, I'm sure that browsers and such make accommodations for that case. You'll have to decide whether to mirror them exactly and produce an invalid If-None-Match header, or to add quotes. It's very likely that either will work equally well in practice.