git.iko.soy/typeable/servant
on master help sign in
Merge pull request #1204 from przembot/fix/issue-1200
7de93f9Alp Mestanogullari
servant-client-core/src/Servant/Client/Core/HasClient.hs+4−6
@@ -253,12 +253,10 @@ instance {-# OVERLAPPING #-}
253 { requestMethod = method
253 { requestMethod = method
254 , requestAccept = fromList $ toList accept
254 , requestAccept = fromList $ toList accept
255 }
255 }
256− case mimeUnrender (Proxy :: Proxy ct) $ responseBody response of
256+ val <- response `decodedAs` (Proxy :: Proxy ct)
257− Left err -> throwClientError $ DecodeFailure (pack err) response
258− Right val -> return $ Headers
259− { getResponse = val
257+ return $ Headers { getResponse = val
260− , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
258+ , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
261− }
259+ }
262 where method = reflectMethod (Proxy :: Proxy method)
260 where method = reflectMethod (Proxy :: Proxy method)
263 accept = contentTypes (Proxy :: Proxy ct)
261 accept = contentTypes (Proxy :: Proxy ct)
264
262
servant-client/test/Servant/ClientTestUtils.hs+2
@@ -168,6 +168,7 @@ type FailApi =
168 "get" :> Raw
168 "get" :> Raw
169 :<|> "capture" :> Capture "name" String :> Raw
169 :<|> "capture" :> Capture "name" String :> Raw
170 :<|> "body" :> Raw
170 :<|> "body" :> Raw
171+ :<|> "headers" :> Raw
171failApi :: Proxy FailApi
172failApi :: Proxy FailApi
172failApi = Proxy
173failApi = Proxy
173
174
@@ -176,6 +177,7 @@ failServer = serve failApi (
176 (Tagged $ \ _request respond -> respond $ Wai.responseLBS HTTP.ok200 [] "")
177 (Tagged $ \ _request respond -> respond $ Wai.responseLBS HTTP.ok200 [] "")
177 :<|> (\ _capture -> Tagged $ \_request respond -> respond $ Wai.responseLBS HTTP.ok200 [("content-type", "application/json")] "")
178 :<|> (\ _capture -> Tagged $ \_request respond -> respond $ Wai.responseLBS HTTP.ok200 [("content-type", "application/json")] "")
178 :<|> (Tagged $ \_request respond -> respond $ Wai.responseLBS HTTP.ok200 [("content-type", "fooooo")] "")
179 :<|> (Tagged $ \_request respond -> respond $ Wai.responseLBS HTTP.ok200 [("content-type", "fooooo")] "")
180+ :<|> (Tagged $ \_request respond -> respond $ Wai.responseLBS HTTP.ok200 [("content-type", "application/x-www-form-urlencoded"), ("X-Example1", "1"), ("X-Example2", "foo")] "")
179 )
181 )
180
182
181-- * basic auth stuff
183-- * basic auth stuff
servant-client/test/Servant/FailSpec.hs+6
@@ -67,6 +67,12 @@ failSpec = beforeAll (startWaiApp failServer) $ afterAll endWaiApp $ do
67 UnsupportedContentType "application/octet-stream" _ -> return ()
67 UnsupportedContentType "application/octet-stream" _ -> return ()
68 _ -> fail $ "expected UnsupportedContentType, but got " <> show res
68 _ -> fail $ "expected UnsupportedContentType, but got " <> show res
69
69
70+ it "reports UnsupportedContentType when there are response headers" $ \(_, baseUrl) -> do
71+ Left res <- runClient getRespHeaders baseUrl
72+ case res of
73+ UnsupportedContentType "application/x-www-form-urlencoded" _ -> return ()
74+ _ -> fail $ "expected UnsupportedContentType, but got " <> show res
75+
70 it "reports InvalidContentTypeHeader" $ \(_, baseUrl) -> do
76 it "reports InvalidContentTypeHeader" $ \(_, baseUrl) -> do
71 let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> getBody :<|> _) = client api
77 let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> getBody :<|> _) = client api
72 Left res <- runClient (getBody alice) baseUrl
78 Left res <- runClient (getBody alice) baseUrl