Code review fixes for #1444
This commit is contained in:
parent
fd872cff40
commit
05b2193e9f
@ -877,10 +877,14 @@ setEtag :: MonadHandler m => Text -> m ()
|
|||||||
setEtag etag = do
|
setEtag etag = do
|
||||||
mmatch <- lookupHeader "if-none-match"
|
mmatch <- lookupHeader "if-none-match"
|
||||||
let matches = maybe [] parseMatch mmatch
|
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
|
then notModified
|
||||||
else addHeader "etag" $ T.concat ["\"", etag, "\""]
|
else addHeader "etag" $ T.concat ["\"", etag, "\""]
|
||||||
|
|
||||||
|
|
||||||
-- | Parse an if-none-match field according to the spec.
|
-- | Parse an if-none-match field according to the spec.
|
||||||
parseMatch :: S.ByteString -> [Etag]
|
parseMatch :: S.ByteString -> [Etag]
|
||||||
parseMatch =
|
parseMatch =
|
||||||
|
|||||||
@ -79,12 +79,14 @@ specs = describe "Redirect" $ do
|
|||||||
res <- request defaultRequest { pathInfo = ["etag"] }
|
res <- request defaultRequest { pathInfo = ["etag"] }
|
||||||
assertStatus 200 res
|
assertStatus 200 res
|
||||||
assertHeader "etag" "\"hello world\"" 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
|
it "single, unquoted if-none-match" $ app $ do
|
||||||
res <- request defaultRequest
|
res <- request defaultRequest
|
||||||
{ pathInfo = ["etag"]
|
{ pathInfo = ["etag"]
|
||||||
, requestHeaders = [("if-none-match", "hello world")]
|
, requestHeaders = [("if-none-match", "hello world")]
|
||||||
}
|
}
|
||||||
assertStatus 200 res
|
assertStatus 304 res
|
||||||
it "different if-none-match" $ app $ do
|
it "different if-none-match" $ app $ do
|
||||||
res <- request defaultRequest
|
res <- request defaultRequest
|
||||||
{ pathInfo = ["etag"]
|
{ pathInfo = ["etag"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user