I need to add a custom header to an HTTP request, and its value's type will be boolean. However, HTTP header values are all strings. So what is the common practice for representing a boolean in this case? 0/1, false/true, False/True, off/on, etc?
E.g.
My-Header: 1
Or what's generally recommended, i.e. the most commonly used convention?
UPDATE: it might make the most sense to use a header exists vs doesn't exist convention as implied here
HTTP Header Operation http header .EXISTS
Returns a Boolean TRUE if an instance of the specified header type exists. Following is an example:
http.req.header("CacheControl").exists
i think the answer is ?0 vs ?1
Structured Field Values for HTTP > 3.3.6. Booleans
Boolean values can be conveyed in Structured Fields.
The ABNF for a Boolean is:
sf-boolean = "?" boolean
boolean = "0" / "1"
A Boolean is indicated with a leading "?" character followed by a "1" for a true value or "0" for false. For example:
Example-Boolean: ?1
check out Sec-Fetch-User:
Syntax
Sec-Fetch-User: ?0
Sec-Fetch-User: ?1
Values
The value is a Boolean Structured Header.
?0 The navigation request was triggered by a user activation.
?1 The navigation request was triggered by something other than a user activation.
but fwiw, Save-Data also seems to be a standard/official "boolean" header that accepts values "on" vs "off"
Save-Data
A boolean that indicates the user agent's preference for reduced data usage.
(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)
A numerical value indicating whether the client wants to opt in to reduced data usage mode.
onindicates yes, whileoff(the default) indicates no.
also confusingly, the ABNF page actually says:
boolean = ( "true" / "1" ) /
( "false" / "0" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With