-
Notifications
You must be signed in to change notification settings - Fork 83
Description
RFC7230 says (emphasis added):
A field value might be preceded and/or followed by optional whitespace (OWS); a single SP preceding the field-value is preferred for consistent readability by humans. The field value does not include any leading or trailing whitespace: OWS occurring before the first non-whitespace octet of the field value or after the last non-whitespace octet of the field value ought to be excluded by parsers when extracting the field value from a header field.
And yet, getHeader currently preserves any trailing optional whitespace (and doesn't even contain a stern warning about this in its Haddock docstring), which can easily result in subtle bugs when not taken into account when processing the field-value as returned by getHeader
I currently have to workaround this via helpers such as
-- | Helper to workaround 'getHeader' currently not stripping trailing WS
getHeaderTrimmed :: HasHeaders a => CI ByteString -> a -> Maybe ByteString
getHeaderTrimmed n rq = rtrim <$> getHeader n rq
where
rtrim = fst . BS.spanEnd isWS
isWS 0x09 = True
isWS 0x20 = True
isWS _ = Falsebut it would be helpful in making getHeader less error-prone if it stripped trailing OWS by default.