From 8574d8d2a9ec3041efbc2459810bb9e363d1a036 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Fri, 10 Nov 2017 23:22:05 +0200 Subject: [PATCH 1/2] Send Accept header in servant-client Fixes #858. The bug was introduced in servant-client-core refactor (servant-client-0.12). See https://github.com/haskell-servant/servant/blob/8973cf56f1feea8830212c05ca2c2682e398499e/servant-client/src/Servant/Common/Req.hs#L151-L179 for the unbroken variant in servant-client-0.11 --- servant-client/CHANGELOG.md | 6 ++++++ servant-client/servant-client.cabal | 2 +- .../src/Servant/Client/Internal/HttpClient.hs | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/servant-client/CHANGELOG.md b/servant-client/CHANGELOG.md index f91629db..c3665a88 100644 --- a/servant-client/CHANGELOG.md +++ b/servant-client/CHANGELOG.md @@ -1,6 +1,12 @@ [The latest version of this document is on GitHub.](https://github.com/haskell-servant/servant/blob/master/servant-client/CHANGELOG.md) [Changelog for `servant` package contains significant entries for all core packages.](https://github.com/haskell-servant/servant/blob/master/servant/CHANGELOG.md) +0.12.0.1 +-------- + +- Send `Accept` header. + ([#858](https://github.com/haskell-servant/servant/issues/858)) + 0.12 ---- diff --git a/servant-client/servant-client.cabal b/servant-client/servant-client.cabal index 79d7667a..fd83a780 100644 --- a/servant-client/servant-client.cabal +++ b/servant-client/servant-client.cabal @@ -1,5 +1,5 @@ name: servant-client -version: 0.12 +version: 0.12.0.1 synopsis: automatical derivation of querying functions for servant webservices description: This library lets you derive automatically Haskell functions that diff --git a/servant-client/src/Servant/Client/Internal/HttpClient.hs b/servant-client/src/Servant/Client/Internal/HttpClient.hs index d116b443..9a479c42 100644 --- a/servant-client/src/Servant/Client/Internal/HttpClient.hs +++ b/servant-client/src/Servant/Client/Internal/HttpClient.hs @@ -28,6 +28,7 @@ import Data.ByteString.Builder (toLazyByteString) import qualified Data.ByteString.Lazy as BSL import Data.Foldable (toList) import Data.Functor.Alt (Alt (..)) +import Data.Maybe (maybeToList) import Data.Monoid ((<>)) import Data.Proxy (Proxy (..)) import Data.Sequence (fromList) @@ -133,16 +134,26 @@ requestToClientRequest burl r = Client.defaultRequest <> toLazyByteString (requestPath r) , Client.queryString = renderQuery True . toList $ requestQueryString r , Client.requestHeaders = - let orig = toList $ requestHeaders r - in maybe orig (: orig) contentTypeHdr + maybeToList acceptHdr ++ maybeToList contentTypeHdr ++ headers , Client.requestBody = body , Client.secure = isSecure } where + -- Content-Type and Accept are specified by requestBody and requestAccept + headers = filter (\(h, _) -> h /= "Accept" && h /= "Content-Type") $ + toList $requestHeaders r + + acceptHdr + | null hs = Nothing + | otherwise = Just ("Accept", renderHeader hs) + where + hs = toList $ requestAccept r + (body, contentTypeHdr) = case requestBody r of Nothing -> (Client.RequestBodyLBS "", Nothing) Just (RequestBodyLBS body', typ) -> (Client.RequestBodyLBS body', Just (hContentType, renderHeader typ)) + isSecure = case baseUrlScheme burl of Http -> False Https -> True From 66cd8b843b8a15a920478db6bcc98d35d874a06f Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Fri, 10 Nov 2017 23:29:48 +0200 Subject: [PATCH 2/2] Build only master and release-0.12 on travis --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6837b302..93388c60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,11 @@ sudo: false git: submodules: false # whether to recursively clone submodules +branches: + only: + - master + - release-0.12 + cache: directories: - $HOME/.cabal/packages