From a1b23018f97add4ccc56fbb50906f8fe0aa89ab5 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 19:46:49 +1000 Subject: [PATCH 1/9] Replace use of ToByteString with HttpApiData for GetHeaders, fixes servant/#581 * Version bump because this changes the API for GetHeaders --- servant-mock/test/Servant/MockSpec.hs | 9 +++++---- servant/CHANGELOG.md | 1 + servant/servant.cabal | 2 +- servant/src/Servant/API/ResponseHeaders.hs | 15 ++++++++------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/servant-mock/test/Servant/MockSpec.hs b/servant-mock/test/Servant/MockSpec.hs index 7d7b32ac..dfbcc0b9 100644 --- a/servant-mock/test/Servant/MockSpec.hs +++ b/servant-mock/test/Servant/MockSpec.hs @@ -8,9 +8,7 @@ module Servant.MockSpec where import Data.Aeson as Aeson -import Data.ByteString.Conversion.To import Data.Proxy -import Data.String import GHC.Generics import Network.Wai import Servant.API @@ -40,8 +38,11 @@ data TestHeader | ArbitraryHeader deriving (Show) -instance ToByteString TestHeader where - builder = fromString . show +instance ToHttpApiData TestHeader where + toHeader = toHeader . show + toUrlPiece _ = error "ToHttpApiData.toUrlPiece not implemented for TestHeader" + toQueryParam _ = error "ToHttpApiData.toQueryParam not implemented for TestHeader" + instance Arbitrary TestHeader where arbitrary = return ArbitraryHeader diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index f35679d1..bff2ed3e 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -2,6 +2,7 @@ next ---- * Add `CaptureAll` combinator. Captures all of the remaining segments in a URL. +* replace use of `ToByteString` with `HttpApiData` for `GetHeaders` 0.8 --- diff --git a/servant/servant.cabal b/servant/servant.cabal index 3c89171f..0f308995 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -1,5 +1,5 @@ name: servant -version: 0.8 +version: 0.8.1 synopsis: A family of combinators for defining webservices APIs description: A family of combinators for defining webservices APIs and serving them diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index cdb7341e..d70f78b5 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -31,8 +31,9 @@ module Servant.API.ResponseHeaders ) where import Data.ByteString.Char8 as BS (pack, unlines, init) -import Data.ByteString.Conversion (ToByteString, toByteString', +import Data.ByteString.Conversion (--ToByteString, toByteString', FromByteString, fromByteString) +import Web.HttpApiData (ToHttpApiData,toHeader) import qualified Data.CaseInsensitive as CI import Data.Proxy import GHC.TypeLits (KnownSymbol, symbolVal) @@ -88,18 +89,18 @@ class GetHeaders ls where instance OVERLAPPING_ GetHeaders (HList '[]) where getHeaders _ = [] -instance OVERLAPPABLE_ ( KnownSymbol h, ToByteString x, GetHeaders (HList xs) ) +instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData x, GetHeaders (HList xs) ) => GetHeaders (HList (Header h x ': xs)) where getHeaders hdrs = case hdrs of - Header val `HCons` rest -> (headerName , toByteString' val):getHeaders rest - UndecodableHeader h `HCons` rest -> (headerName, h) : getHeaders rest + Header val `HCons` rest -> (headerName , toHeader val):getHeaders rest + UndecodableHeader h `HCons` rest -> (headerName, h) :getHeaders rest MissingHeader `HCons` rest -> getHeaders rest where headerName = CI.mk . pack $ symbolVal (Proxy :: Proxy h) instance OVERLAPPING_ GetHeaders (Headers '[] a) where getHeaders _ = [] -instance OVERLAPPABLE_ ( KnownSymbol h, GetHeaders (HList rest), ToByteString v ) +instance OVERLAPPABLE_ ( KnownSymbol h, GetHeaders (HList rest), ToHttpApiData v ) => GetHeaders (Headers (Header h v ': rest) a) where getHeaders hs = getHeaders $ getHeadersHList hs @@ -111,11 +112,11 @@ class AddHeader h v orig new addHeader :: v -> orig -> new -- ^ N.B.: The same header can't be added multiple times -instance OVERLAPPING_ ( KnownSymbol h, ToByteString v ) +instance OVERLAPPING_ ( KnownSymbol h, ToHttpApiData v ) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': fst ': rest) a) where addHeader a (Headers resp heads) = Headers resp (HCons (Header a) heads) -instance OVERLAPPABLE_ ( KnownSymbol h, ToByteString v +instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v , new ~ (Headers '[Header h v] a) ) => AddHeader h v a new where addHeader a resp = Headers resp (HCons (Header a) HNil) From 85a6d9714cd9d8cf9cc1dab08b46f1add25727d5 Mon Sep 17 00:00:00 2001 From: Christine Koppelt Date: Fri, 2 Sep 2016 12:43:22 +0200 Subject: [PATCH 2/9] add 'stack setup' command --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4eb4705..58aaca53 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,9 +8,10 @@ repository. You can use `cabal`: ./scripts/test-all.sh # Run all the tests ``` -`stack`: +Or `stack`: ```shell +stack setup # Downloads and installs a proper GHC version if necessary stack build # Install and build packages stack test # Run all the tests ``` From 9b5a564f3c151c699a6ee16c7e0dfc9564fcc1f8 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 23:14:45 +1000 Subject: [PATCH 3/9] Remove dependency on bytestring-conversion --- servant/servant.cabal | 1 - servant/src/Servant/API/ResponseHeaders.hs | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/servant/servant.cabal b/servant/servant.cabal index 0f308995..56a2cc6e 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -54,7 +54,6 @@ library , aeson >= 0.7 && < 1.1 , attoparsec >= 0.12 && < 0.14 , bytestring >= 0.10 && < 0.11 - , bytestring-conversion >= 0.3 && < 0.4 , case-insensitive >= 1.2 && < 1.3 , http-api-data >= 0.1 && < 0.3 , http-media >= 0.4 && < 0.7 diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index d70f78b5..1ddba9d0 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -31,9 +31,8 @@ module Servant.API.ResponseHeaders ) where import Data.ByteString.Char8 as BS (pack, unlines, init) -import Data.ByteString.Conversion (--ToByteString, toByteString', - FromByteString, fromByteString) -import Web.HttpApiData (ToHttpApiData,toHeader) +import Web.HttpApiData (ToHttpApiData,toHeader + ,FromHttpApiData,parseHeader) import qualified Data.CaseInsensitive as CI import Data.Proxy import GHC.TypeLits (KnownSymbol, symbolVal) @@ -69,17 +68,17 @@ class BuildHeadersTo hs where instance OVERLAPPING_ BuildHeadersTo '[] where buildHeadersTo _ = HNil -instance OVERLAPPABLE_ ( FromByteString v, BuildHeadersTo xs, KnownSymbol h ) +instance OVERLAPPABLE_ ( FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h ) => BuildHeadersTo ((Header h v) ': xs) where buildHeadersTo headers = let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h) matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers in case matching of [] -> MissingHeader `HCons` buildHeadersTo headers - xs -> case fromByteString (BS.init $ BS.unlines xs) of - Nothing -> UndecodableHeader (BS.init $ BS.unlines xs) + xs -> case parseHeader (BS.init $ BS.unlines xs) of + Left _err -> UndecodableHeader (BS.init $ BS.unlines xs) `HCons` buildHeadersTo headers - Just h -> Header h `HCons` buildHeadersTo headers + Right h -> Header h `HCons` buildHeadersTo headers -- * Getting From 5bef76ed03772d271be55801f6bc480cbe8f7baf Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 23:27:37 +1000 Subject: [PATCH 4/9] Remove all use of bytestring-conversion --- servant-docs/servant-docs.cabal | 2 -- servant-docs/src/Servant/Docs/Internal.hs | 5 ++--- servant-mock/servant-mock.cabal | 1 - servant-server/servant-server.cabal | 1 - servant-server/test/Servant/ServerSpec.hs | 1 - 5 files changed, 2 insertions(+), 8 deletions(-) diff --git a/servant-docs/servant-docs.cabal b/servant-docs/servant-docs.cabal index d325e3d9..d34ac9b4 100644 --- a/servant-docs/servant-docs.cabal +++ b/servant-docs/servant-docs.cabal @@ -36,7 +36,6 @@ library , aeson , aeson-pretty , bytestring - , bytestring-conversion , case-insensitive , hashable , http-media >= 0.6 @@ -61,7 +60,6 @@ executable greet-docs build-depends: base , aeson - , bytestring-conversion , lens , servant , servant-docs diff --git a/servant-docs/src/Servant/Docs/Internal.hs b/servant-docs/src/Servant/Docs/Internal.hs index 7b181822..70530455 100644 --- a/servant-docs/src/Servant/Docs/Internal.hs +++ b/servant-docs/src/Servant/Docs/Internal.hs @@ -25,7 +25,6 @@ import Control.Arrow (second) import Control.Lens (makeLenses, mapped, over, traversed, view, (%~), (&), (.~), (<>~), (^.), (|>)) import qualified Control.Monad.Omega as Omega -import Data.ByteString.Conversion (ToByteString, toByteString) import Data.ByteString.Lazy.Char8 (ByteString) import qualified Data.ByteString.Char8 as BSC import qualified Data.CaseInsensitive as CI @@ -461,12 +460,12 @@ class AllHeaderSamples ls where instance AllHeaderSamples '[] where allHeaderToSample _ = [] -instance (ToByteString l, AllHeaderSamples ls, ToSample l, KnownSymbol h) +instance (ToHttpApiData l, AllHeaderSamples ls, ToSample l, KnownSymbol h) => AllHeaderSamples (Header h l ': ls) where allHeaderToSample _ = mkHeader (toSample (Proxy :: Proxy l)) : allHeaderToSample (Proxy :: Proxy ls) where headerName = CI.mk . cs $ symbolVal (Proxy :: Proxy h) - mkHeader (Just x) = (headerName, cs $ toByteString x) + mkHeader (Just x) = (headerName, cs $ toHeader x) mkHeader Nothing = (headerName, "") -- | Synthesise a sample value of a type, encoded in the specified media types. diff --git a/servant-mock/servant-mock.cabal b/servant-mock/servant-mock.cabal index 89ff1f6f..64e012b0 100644 --- a/servant-mock/servant-mock.cabal +++ b/servant-mock/servant-mock.cabal @@ -69,5 +69,4 @@ test-suite spec servant-server, servant-mock, aeson, - bytestring-conversion, wai diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index d055df2f..44a787fa 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -114,7 +114,6 @@ test-suite spec , aeson , base64-bytestring , bytestring - , bytestring-conversion , directory , exceptions , hspec == 2.* diff --git a/servant-server/test/Servant/ServerSpec.hs b/servant-server/test/Servant/ServerSpec.hs index 2337c258..ade5a7b3 100644 --- a/servant-server/test/Servant/ServerSpec.hs +++ b/servant-server/test/Servant/ServerSpec.hs @@ -17,7 +17,6 @@ import Control.Monad (forM_, when, unless) import Control.Monad.Trans.Except (throwE) import Data.Aeson (FromJSON, ToJSON, decode', encode) import qualified Data.ByteString.Base64 as Base64 -import Data.ByteString.Conversion () import Data.Char (toUpper) import Data.Monoid import Data.Proxy (Proxy (Proxy)) From a991cbe77c0a951a39b942fa684b9e9898ac13c2 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 23:53:18 +1000 Subject: [PATCH 5/9] Revert version bump, update changelog --- servant/CHANGELOG.md | 2 +- servant/servant.cabal | 2 +- servant/src/Servant/API/ResponseHeaders.hs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index bff2ed3e..f5973555 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -2,7 +2,7 @@ next ---- * Add `CaptureAll` combinator. Captures all of the remaining segments in a URL. -* replace use of `ToByteString` with `HttpApiData` for `GetHeaders` +* BACKWARDS INCOMPATIBLE replace use of `ToFromByteString` with `To/FromHttpApiData` for `GetHeaders/BuildHeadersTo` 0.8 --- diff --git a/servant/servant.cabal b/servant/servant.cabal index 56a2cc6e..d3607935 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -1,5 +1,5 @@ name: servant -version: 0.8.1 +version: 0.8 synopsis: A family of combinators for defining webservices APIs description: A family of combinators for defining webservices APIs and serving them diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index 1ddba9d0..99bd72b6 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -31,8 +31,8 @@ module Servant.API.ResponseHeaders ) where import Data.ByteString.Char8 as BS (pack, unlines, init) -import Web.HttpApiData (ToHttpApiData,toHeader - ,FromHttpApiData,parseHeader) +import Web.HttpApiData (ToHttpApiData, toHeader + ,FromHttpApiData, parseHeader) import qualified Data.CaseInsensitive as CI import Data.Proxy import GHC.TypeLits (KnownSymbol, symbolVal) From dbab31508ee21f1ece729a1560d417a726e9c287 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 23:59:36 +1000 Subject: [PATCH 6/9] Comma style is hard --- servant/src/Servant/API/ResponseHeaders.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index 99bd72b6..deacb90b 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -31,8 +31,8 @@ module Servant.API.ResponseHeaders ) where import Data.ByteString.Char8 as BS (pack, unlines, init) -import Web.HttpApiData (ToHttpApiData, toHeader - ,FromHttpApiData, parseHeader) +import Web.HttpApiData (ToHttpApiData, toHeader, + FromHttpApiData, parseHeader) import qualified Data.CaseInsensitive as CI import Data.Proxy import GHC.TypeLits (KnownSymbol, symbolVal) From 3e704362c34a730aee05f187bbdcf87ffd658214 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Sat, 3 Sep 2016 00:23:21 +1000 Subject: [PATCH 7/9] Remove error calls and replace with working implementations of ToHttpApiData --- servant-mock/test/Servant/MockSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servant-mock/test/Servant/MockSpec.hs b/servant-mock/test/Servant/MockSpec.hs index dfbcc0b9..83401c73 100644 --- a/servant-mock/test/Servant/MockSpec.hs +++ b/servant-mock/test/Servant/MockSpec.hs @@ -40,8 +40,8 @@ data TestHeader instance ToHttpApiData TestHeader where toHeader = toHeader . show - toUrlPiece _ = error "ToHttpApiData.toUrlPiece not implemented for TestHeader" - toQueryParam _ = error "ToHttpApiData.toQueryParam not implemented for TestHeader" + toUrlPiece = toUrlPiece . show + toQueryParam = toQueryParam . show instance Arbitrary TestHeader where From 47eed38ee6a595ac24fd7b550c5efe9043890af5 Mon Sep 17 00:00:00 2001 From: Cornelius Diekmann Date: Fri, 2 Sep 2016 16:38:03 +0200 Subject: [PATCH 8/9] Fixed typo: s/real/realm/ Actually, I'm just trying to learn servant and I'm reading the doc for the first time. But this just looks like a typo to me. --- doc/tutorial/ApiType.lhs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorial/ApiType.lhs b/doc/tutorial/ApiType.lhs index 096903e8..3aa4c844 100644 --- a/doc/tutorial/ApiType.lhs +++ b/doc/tutorial/ApiType.lhs @@ -319,8 +319,8 @@ Which is used like so: ``` haskell type ProtectedAPI12 - = UserAPI -- this is public - :<|> BasicAuth "my-real" User :> UserAPI2 -- this is protected by auth + = UserAPI -- this is public + :<|> BasicAuth "my-realm" User :> UserAPI2 -- this is protected by auth ``` ### Interoperability with `wai`: `Raw` From bf824a3889f4c1483ffc6ad816f9f6ae87ddbbcc Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Fri, 2 Sep 2016 13:09:47 -0300 Subject: [PATCH 9/9] Bump version to 0.8.1 --- doc/tutorial/tutorial.cabal | 2 +- servant-client/servant-client.cabal | 2 +- servant-docs/servant-docs.cabal | 2 +- servant-foreign/servant-foreign.cabal | 2 +- servant-js/servant-js.cabal | 2 +- servant-mock/servant-mock.cabal | 2 +- servant-server/servant-server.cabal | 2 +- servant/CHANGELOG.md | 2 +- servant/servant.cabal | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/tutorial/tutorial.cabal b/doc/tutorial/tutorial.cabal index 3b90c0dc..797ff5e2 100644 --- a/doc/tutorial/tutorial.cabal +++ b/doc/tutorial/tutorial.cabal @@ -1,5 +1,5 @@ name: tutorial -version: 0.8 +version: 0.8.1 synopsis: The servant tutorial homepage: http://haskell-servant.readthedocs.org/ license: BSD3 diff --git a/servant-client/servant-client.cabal b/servant-client/servant-client.cabal index 089e1209..edbca092 100644 --- a/servant-client/servant-client.cabal +++ b/servant-client/servant-client.cabal @@ -1,5 +1,5 @@ name: servant-client -version: 0.8 +version: 0.8.1 synopsis: automatical derivation of querying functions for servant webservices description: This library lets you derive automatically Haskell functions that diff --git a/servant-docs/servant-docs.cabal b/servant-docs/servant-docs.cabal index d325e3d9..a194b763 100644 --- a/servant-docs/servant-docs.cabal +++ b/servant-docs/servant-docs.cabal @@ -1,5 +1,5 @@ name: servant-docs -version: 0.8 +version: 0.8.1 synopsis: generate API docs for your servant webservice description: Library for generating API docs from a servant API definition. diff --git a/servant-foreign/servant-foreign.cabal b/servant-foreign/servant-foreign.cabal index ea5b599a..26be4dbd 100644 --- a/servant-foreign/servant-foreign.cabal +++ b/servant-foreign/servant-foreign.cabal @@ -1,5 +1,5 @@ name: servant-foreign -version: 0.8 +version: 0.8.1 synopsis: Helpers for generating clients for servant APIs in any programming language description: Helper types and functions for generating client functions for servant APIs in any programming language diff --git a/servant-js/servant-js.cabal b/servant-js/servant-js.cabal index 726e0b4e..04ea1ff9 100644 --- a/servant-js/servant-js.cabal +++ b/servant-js/servant-js.cabal @@ -1,5 +1,5 @@ name: servant-js -version: 0.8 +version: 0.8.1 synopsis: Automatically derive javascript functions to query servant webservices. description: Automatically derive javascript functions to query servant webservices. diff --git a/servant-mock/servant-mock.cabal b/servant-mock/servant-mock.cabal index 89ff1f6f..e4610e96 100644 --- a/servant-mock/servant-mock.cabal +++ b/servant-mock/servant-mock.cabal @@ -1,5 +1,5 @@ name: servant-mock -version: 0.8 +version: 0.8.1 synopsis: Derive a mock server for free from your servant API types description: Derive a mock server for free from your servant API types diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index d055df2f..04ad5fa3 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -1,5 +1,5 @@ name: servant-server -version: 0.8 +version: 0.8.1 synopsis: A family of combinators for defining webservices APIs and serving them description: A family of combinators for defining webservices APIs and serving them diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index f35679d1..c409c960 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -1,4 +1,4 @@ -next +0.8.1 ---- * Add `CaptureAll` combinator. Captures all of the remaining segments in a URL. diff --git a/servant/servant.cabal b/servant/servant.cabal index 3c89171f..0f308995 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -1,5 +1,5 @@ name: servant -version: 0.8 +version: 0.8.1 synopsis: A family of combinators for defining webservices APIs description: A family of combinators for defining webservices APIs and serving them