Is there any method that already implements proper ETag quoting for http headers?
As pointed out in Syntax for ETag? the proper way is not as trivial as putting double quotes around it.
Couldn't find anything obvious.
Is there any method that already implements proper ETag quoting for http headers?
As pointed out in Syntax for ETag? the proper way is not as trivial as putting double quotes around it.
Couldn't find anything obvious.
That's kind of misleading. The quotes are an integral part of the ETag, so there's no transition from "unquoted ETag" to "quoted ETag".
If what you're after is a way to include characters not allowed in ETags, you'll just to invent a custom escaping syntax. Which one doesn't matter, because your server is producing and consuming them, and for clients they are fully opaque.
That answer is based on a previous version of the ETag specification. The current one (RFC 7232) explicitly disallows the use of the double-quote character within the opaque ETag.
So assuming that the opaque part of your ETag is valid according to RFC 7232, it really is as simple as putting double quotes around it.
However, I recommend that instead of doing that you require whoever is providing the ETag to include the double quotes. That's because they are necessary to distinguish weak ETags. Without them you are left with a more complicated API, or more commonly, no way to specify weak ETags at all.