Syntax for ETag?

Pacerier picture Pacerier · Jul 16, 2011 · Viewed 12.4k times · Source

Redbot reports that my webpage has invalid header:

The ETag header's syntax isn't valid.

My headers are set to:

ETag: 4ae413bd

Why is it invalid?

What is the syntax for an ETag?

Answer

Pacerier picture Pacerier · Jul 20, 2012

Try ETag: "4ae413bd". The value of an ETag must follow the ABNF form:

  entity-tag = [ weak ] opaque-tag
  weak       = "W/"
  opaque-tag = quoted-string

  quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
  qdtext         = <any TEXT except <">>
  quoted-pair    = "\" CHAR
  CHAR           = <any US-ASCII character (octets 0 - 127)>
  TEXT           = <any OCTET except CTLs, but including LWS>
  OCTET          = <any 8-bit sequence of data>
  LWS            = [CRLF] 1*( SP | HT )
  CTL            = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
  CRLF           = CR LF
  CR             = <US-ASCII CR, carriage return (13)>
  LF             = <US-ASCII LF, linefeed (10)>
  SP             = <US-ASCII SP, space (32)>
  HT             = <US-ASCII HT, horizontal-tab (9)>

, which is basically ([wW]/)?"([^"]|\\")*" in regular regex.

Note that both "\" and "/" are valid values for etags.

References: section-14.19, section-3.11, section-2.2.