Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getHeader doesn't trim trailing OWS #292

Open
hvr opened this issue Dec 19, 2019 · 0 comments
Open

getHeader doesn't trim trailing OWS #292

hvr opened this issue Dec 19, 2019 · 0 comments

Comments

@hvr
Copy link
Member

hvr commented Dec 19, 2019

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 _    = False

but it would be helpful in making getHeader less error-prone if it stripped trailing OWS by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant