Code review fixes for #1444

This commit is contained in:
Ian Duncan 2017-09-08 09:00:12 +09:00
parent fd872cff40
commit 05b2193e9f
No known key found for this signature in database
GPG Key ID: CC6C9D28854569E7
2 changed files with 8 additions and 2 deletions

View File

@ -877,10 +877,14 @@ setEtag :: MonadHandler m => Text -> m ()
setEtag etag = do
mmatch <- lookupHeader "if-none-match"
let matches = maybe [] parseMatch mmatch
if StrongEtag (encodeUtf8 etag) `elem` matches
baseTag = encodeUtf8 etag
strongTag = StrongEtag baseTag
badTag = InvalidEtag baseTag
if any (\tag -> tag == strongTag || tag == badTag) matches
then notModified
else addHeader "etag" $ T.concat ["\"", etag, "\""]
-- | Parse an if-none-match field according to the spec.
parseMatch :: S.ByteString -> [Etag]
parseMatch =

View File

@ -79,12 +79,14 @@ specs = describe "Redirect" $ do
res <- request defaultRequest { pathInfo = ["etag"] }
assertStatus 200 res
assertHeader "etag" "\"hello world\"" res
-- Note: this violates the RFC around ETag format, but is being left as is
-- out of concerns that it might break existing users with misbehaving clients.
it "single, unquoted if-none-match" $ app $ do
res <- request defaultRequest
{ pathInfo = ["etag"]
, requestHeaders = [("if-none-match", "hello world")]
}
assertStatus 200 res
assertStatus 304 res
it "different if-none-match" $ app $ do
res <- request defaultRequest
{ pathInfo = ["etag"]