@@ -102,7 +102,6 @@
102{-# LANGUAGE ScopedTypeVariables #-}
102{-# LANGUAGE ScopedTypeVariables #-}
103{-# LANGUAGE TypeFamilies #-}
103{-# LANGUAGE TypeFamilies #-}
104{-# LANGUAGE UndecidableInstances #-}
104{-# LANGUAGE UndecidableInstances #-}
105−{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
107module Network.HTTP.Req
106module Network.HTTP.Req
108 ( -- * Making a request
107 ( -- * Making a request
@@ -391,8 +390,13 @@ req
391 -> Proxy response -- ^ A hint how to interpret response
390 -> Proxy response -- ^ A hint how to interpret response
392 -> Option scheme -- ^ Collection of optional parameters
391 -> Option scheme -- ^ Collection of optional parameters
393 -> m response -- ^ Response
392 -> m response -- ^ Response
394−req method url body Proxy options =
393+req method url body responseProxy options =
395− reqBr method url body options getHttpResponse
394+ reqBr method url body (options <> extraOptions) getHttpResponse
397+ case acceptHeader responseProxy of
399+ Just accept -> header "Accept" accept
397-- | A version of 'req' that does not use one of the predefined instances of
401-- | A version of 'req' that does not use one of the predefined instances of
398-- 'HttpResponse' but instead allows the user to consume @'L.Response'
402-- 'HttpResponse' but instead allows the user to consume @'L.Response'
@@ -1440,6 +1444,7 @@ instance FromJSON a => HttpResponse (JsonResponse a) where
1440 case A.eitherDecode (BL.fromChunks chunks) of
1444 case A.eitherDecode (BL.fromChunks chunks) of
1441 Left e -> throwIO (JsonHttpException e)
1445 Left e -> throwIO (JsonHttpException e)
1442 Right x -> return $ JsonResponse (x <$ r)
1446 Right x -> return $ JsonResponse (x <$ r)
1447+ acceptHeader Proxy = Just "application/json"
1444-- | Use this as the fourth argument of 'req' to specify that you want it to
1449-- | Use this as the fourth argument of 'req' to specify that you want it to
1445-- return the 'JsonResponse' interpretation.
1450-- return the 'JsonResponse' interpretation.
@@ -1637,6 +1642,18 @@ class HttpResponse response where
1637 -> IO response
1642 -> IO response
1638 -- ^ The final result
1643 -- ^ The final result
1645+ -- | The value of @\"Accept\"@ header. This is useful, for example, if a
1646+ -- website supports both @XML@ and @JSON@ responses, and decides what to
1647+ -- reply with based on what @Accept@ headers you have sent.
1649+ -- __Note__: manually specified 'Options' that set the @\"Accept\"@ header
1650+ -- will take precedence.
1654+ acceptHeader :: Proxy response -> Maybe ByteString
1655+ acceptHeader Proxy = Nothing
1640----------------------------------------------------------------------------
1657----------------------------------------------------------------------------