@@ -101,9 +101,10 @@ spec = do
101 it "works" $ do
101 it "works" $ do
102 r <- req GET (httpbin /: "headers")
102 r <- req GET (httpbin /: "headers")
103 NoReqBody jsonResponse (header "Foo" "bar" <> header "Baz" "quux")
103 NoReqBody jsonResponse (header "Foo" "bar" <> header "Baz" "quux")
104− responseBody r `shouldBe` object
104+ stripFunnyHeaders (responseBody r) `shouldBe` object
105 [ "headers" .= object
105 [ "headers" .= object
106 [ "Accept-Encoding" .= ("gzip" :: Text)
106 [ "Accept-Encoding" .= ("gzip" :: Text)
107+ , "Connection" .= ("close" :: Text)
107 , "Foo" .= ("bar" :: Text)
108 , "Foo" .= ("bar" :: Text)
108 , "Baz" .= ("quux" :: Text)
109 , "Baz" .= ("quux" :: Text)
109 , "Host" .= ("httpbin.org" :: Text) ] ]
110 , "Host" .= ("httpbin.org" :: Text) ] ]
@@ -113,11 +114,12 @@ spec = do
113 describe "receiving GET data back" $
114 describe "receiving GET data back" $
114 it "works" $ do
115 it "works" $ do
115 r <- req GET (httpbin /: "get") NoReqBody jsonResponse mempty
116 r <- req GET (httpbin /: "get") NoReqBody jsonResponse mempty
116− stripOrigin (responseBody r) `shouldBe` object
117+ (stripFunnyHeaders . stripOrigin) (responseBody r) `shouldBe` object
117 [ "args" .= emptyObject
118 [ "args" .= emptyObject
118 , "url" .= ("https://httpbin.org/get" :: Text)
119 , "url" .= ("https://httpbin.org/get" :: Text)
119 , "headers" .= object
120 , "headers" .= object
120 [ "Accept-Encoding" .= ("gzip" :: Text)
121 [ "Accept-Encoding" .= ("gzip" :: Text)
122+ , "Connection" .= ("close" :: Text)
121 , "Host" .= ("httpbin.org" :: Text) ] ]
123 , "Host" .= ("httpbin.org" :: Text) ] ]
122 responseHeader r "Content-Type" `shouldBe` return "application/json"
124 responseHeader r "Content-Type" `shouldBe` return "application/json"
123 responseStatusCode r `shouldBe` 200
125 responseStatusCode r `shouldBe` 200
@@ -128,7 +130,7 @@ spec = do
128 let text = "foo" :: Text
130 let text = "foo" :: Text
129 reflected = reflectJSON text
131 reflected = reflectJSON text
130 r <- req POST (httpbin /: "post") (ReqBodyJson text) jsonResponse mempty
132 r <- req POST (httpbin /: "post") (ReqBodyJson text) jsonResponse mempty
131− stripOrigin (responseBody r) `shouldBe` object
133+ (stripFunnyHeaders . stripOrigin) (responseBody r) `shouldBe` object
132 [ "args" .= emptyObject
134 [ "args" .= emptyObject
133 , "json" .= text
135 , "json" .= text
134 , "data" .= reflected
136 , "data" .= reflected
@@ -136,6 +138,7 @@ spec = do
136 , "headers" .= object
138 , "headers" .= object
137 [ "Content-Type" .= ("application/json; charset=utf-8" :: Text)
139 [ "Content-Type" .= ("application/json; charset=utf-8" :: Text)
138 , "Accept-Encoding" .= ("gzip" :: Text)
140 , "Accept-Encoding" .= ("gzip" :: Text)
141+ , "Connection" .= ("close" :: Text)
139 , "Host" .= ("httpbin.org" :: Text)
142 , "Host" .= ("httpbin.org" :: Text)
140 , "Content-Length" .= show (T.length reflected) ]
143 , "Content-Length" .= show (T.length reflected) ]
141 , "files" .= emptyObject
144 , "files" .= emptyObject
@@ -151,7 +154,7 @@ spec = do
151 , LM.partBS "bar" "bar data!" ]
154 , LM.partBS "bar" "bar data!" ]
152 r <- req POST (httpbin /: "post") body jsonResponse mempty
155 r <- req POST (httpbin /: "post") body jsonResponse mempty
153 let Just contentType = getRequestContentType body
156 let Just contentType = getRequestContentType body
154− stripOrigin (responseBody r) `shouldBe` object
157+ (stripFunnyHeaders . stripOrigin) (responseBody r) `shouldBe` object
155 [ "args" .= emptyObject
158 [ "args" .= emptyObject
156 , "json" .= Null
159 , "json" .= Null
157 , "data" .= ("" :: Text)
160 , "data" .= ("" :: Text)
@@ -159,6 +162,7 @@ spec = do
159 , "headers" .= object
162 , "headers" .= object
160 [ "Content-Type" .= T.decodeUtf8 contentType
163 [ "Content-Type" .= T.decodeUtf8 contentType
161 , "Accept-Encoding" .= ("gzip" :: Text)
164 , "Accept-Encoding" .= ("gzip" :: Text)
165+ , "Connection" .= ("close" :: Text)
162 , "Host" .= ("httpbin.org" :: Text)
166 , "Host" .= ("httpbin.org" :: Text)
163 , "Content-Length" .= ("242" :: Text)
167 , "Content-Length" .= ("242" :: Text)
@@ -177,13 +181,14 @@ spec = do
177 file = "httpbin-data/robots.txt"
181 file = "httpbin-data/robots.txt"
178 contents <- TIO.readFile file
182 contents <- TIO.readFile file
179 r <- req PATCH (httpbin /: "patch") (ReqBodyFile file) jsonResponse mempty
183 r <- req PATCH (httpbin /: "patch") (ReqBodyFile file) jsonResponse mempty
180− stripOrigin (responseBody r) `shouldBe` object
184+ (stripFunnyHeaders . stripOrigin) (responseBody r) `shouldBe` object
181 [ "args" .= emptyObject
185 [ "args" .= emptyObject
182 , "json" .= Null
186 , "json" .= Null
183 , "data" .= contents
187 , "data" .= contents
184 , "url" .= ("https://httpbin.org/patch" :: Text)
188 , "url" .= ("https://httpbin.org/patch" :: Text)
185 , "headers" .= object
189 , "headers" .= object
186 [ "Accept-Encoding" .= ("gzip" :: Text)
190 [ "Accept-Encoding" .= ("gzip" :: Text)
191+ , "Connection" .= ("close" :: Text)
187 , "Host" .= ("httpbin.org" :: Text)
192 , "Host" .= ("httpbin.org" :: Text)
188 , "Content-Length" .= show (T.length contents) ]
193 , "Content-Length" .= show (T.length contents) ]
189 , "files" .= emptyObject
194 , "files" .= emptyObject
@@ -198,7 +203,7 @@ spec = do
198 "baz" =: (5 :: Int) <>
203 "baz" =: (5 :: Int) <>
199 queryFlag "quux"
204 queryFlag "quux"
200 r <- req PUT (httpbin /: "put") (ReqBodyUrlEnc params) jsonResponse mempty
205 r <- req PUT (httpbin /: "put") (ReqBodyUrlEnc params) jsonResponse mempty
201− stripOrigin (responseBody r) `shouldBe` object
206+ (stripFunnyHeaders . stripOrigin) (responseBody r) `shouldBe` object
202 [ "args" .= emptyObject
207 [ "args" .= emptyObject
203 , "json" .= Null
208 , "json" .= Null
204 , "data" .= ("" :: Text)
209 , "data" .= ("" :: Text)
@@ -206,6 +211,7 @@ spec = do
206 , "headers" .= object
211 , "headers" .= object
207 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text)
212 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text)
208 , "Accept-Encoding" .= ("gzip" :: Text)
213 , "Accept-Encoding" .= ("gzip" :: Text)
214+ , "Connection" .= ("close" :: Text)
209 , "Host" .= ("httpbin.org" :: Text)
215 , "Host" .= ("httpbin.org" :: Text)
210 , "Content-Length" .= ("18" :: Text) ]
216 , "Content-Length" .= ("18" :: Text) ]
211 , "files" .= emptyObject
217 , "files" .= emptyObject
@@ -372,6 +378,22 @@ stripOrigin :: Value -> Value
372stripOrigin (Object m) = Object (HM.delete "origin" m)
378stripOrigin (Object m) = Object (HM.delete "origin" m)
373stripOrigin value = value
379stripOrigin value = value
381+-- | Remove funny headers that might break the tests.
383+stripFunnyHeaders :: Value -> Value
384+stripFunnyHeaders (Object m) =
385+ let f (Object p) = Object $ HM.filterWithKey (\k _ -> k `elem` hs) p
387+ hs = [ "Content-Type"
394+ in Object (HM.adjust f "headers" m)
395+stripFunnyHeaders value = value
375-- | This is a complete test case that makes use of <https://httpbin.org> to
397-- | This is a complete test case that makes use of <https://httpbin.org> to
376-- get various response status codes.
398-- get various response status codes.