@@ -1,5 +1,6 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE RankNTypes #-}
5{-# OPTIONS_GHC -fno-warn-orphans #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
@@ -77,14 +78,11 @@ spec = do
78 jsonResponse
79 jsonResponse
79 (header "Foo" "bar" <> header "Baz" "quux")
80 (header "Foo" "bar" <> header "Baz" "quux")
80− stripFunnyHeaders (responseBody r)
81+ stripFunnyHeaders' (responseBody r)
81 `shouldBe` object
82 `shouldBe` object
84− [ "Accept-Encoding" .= ("gzip" :: Text),
83+ [ "Accept-Encoding" .= ("gzip" :: Text),
85− "Foo" .= ("bar" :: Text),
84+ "Foo" .= ("bar" :: Text),
86− "Baz" .= ("quux" :: Text)
85+ "Baz" .= ("quux" :: Text)
89 responseStatusCode r `shouldBe` 200
87 responseStatusCode r `shouldBe` 200
90 responseStatusMessage r `shouldBe` "OK"
88 responseStatusMessage r `shouldBe` "OK"
@@ -383,19 +381,36 @@ stripOrigin value = value
384-- | Remove funny headers that might break the tests.
382-- | Remove funny headers that might break the tests.
385stripFunnyHeaders :: Value -> Value
383stripFunnyHeaders :: Value -> Value
386−stripFunnyHeaders (Object m) =
384+stripFunnyHeaders = \case
388+ ( Aeson.KeyMap.alterF
389+ (pure . fmap stripFunnyHeaders')
396+-- | Similar to 'stripFunnyHeaders', but acts directly on the argument
397+-- without trying to access its "headers" field.
398+stripFunnyHeaders' :: Value -> Value
399+stripFunnyHeaders' = \case
387− let f (Object p) = Object $ Aeson.KeyMap.filterWithKey (\k _ -> k `elem` hs) p
402+ Aeson.KeyMap.filterWithKey
403+ (\k _ -> k `elem` whitelistedHeaders)
388− f value = value
405+ value -> value
407+ whitelistedHeaders =
390− [ "Content-Type",
408+ [ "Content-Type",
391− "Accept-Encoding",
409+ "Accept-Encoding",
393− "Content-Length",
410+ "Content-Length",
397− in Object (runIdentity (Aeson.KeyMap.alterF (pure . fmap f) "headers" m))
398−stripFunnyHeaders value = value
400-- | This is a complete test case that makes use of <https://httpbun.org> to
415-- | This is a complete test case that makes use of <https://httpbun.org> to
401-- get various response status codes.
416-- get various response status codes.