Skip to content

Commit e922b98

Browse files
authored
Merge pull request #1130 from phadej/refactor-servant-client
Refactor servant-client-core
2 parents c462019 + 775b553 commit e922b98

File tree

33 files changed

+252
-509
lines changed

33 files changed

+252
-509
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**/*/dist
2-
dist-newstyle
2+
dist-*
33
.ghc.environment.*
44
/bin
55
/lib

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ install:
103103
- "echo 'allow-newer: servant-quickcheck:servant-server' >> cabal.project"
104104
- "echo 'allow-newer: servant-quickcheck:hspec' >> cabal.project"
105105
- "echo 'allow-newer: servant-quickcheck:http-client' >> cabal.project"
106+
- "echo 'reorder-goals: True' >> cabal.project"
106107
- "echo 'optimization: False' >> cabal.project "
107108
- touch cabal.project.local
108109
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-hoist-server-with-context|cookbook-https|cookbook-jwt-and-basic-auth|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
@@ -184,6 +185,7 @@ script:
184185
- "echo 'allow-newer: servant-quickcheck:servant-server' >> cabal.project"
185186
- "echo 'allow-newer: servant-quickcheck:hspec' >> cabal.project"
186187
- "echo 'allow-newer: servant-quickcheck:http-client' >> cabal.project"
188+
- "echo 'reorder-goals: True' >> cabal.project"
187189
- "echo 'optimization: False' >> cabal.project "
188190
- touch cabal.project.local
189191
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-hoist-server-with-context|cookbook-https|cookbook-jwt-and-basic-auth|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# With common maintenance tasks
2+
3+
all :
4+
@echo "Don't try to make all at once!"
5+
6+
build-ghc :
7+
cabal v2-build all
8+
9+
build-ghcjs :
10+
cabal v2-build --builddir=dist-newstyle-ghcjs --project-file=cabal.ghcjs.project all
11+
12+
packdeps :
13+
packdeps */*.cabal

cabal.ghcjs.project

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
-- Using https://launchpad.net/~hvr/+archive/ubuntu/ghcjs
2-
--
3-
-- $ cabal new-build --project-file cabal.ghcjs.project all -w /opt/ghcjs/8.4/bin/ghcjs
42

53
packages:
64
servant/
@@ -9,16 +7,3 @@ packages:
97

108
-- we need to tell cabal we are using GHCJS
119
compiler: ghcjs
12-
13-
-- https://github.com/ghcjs/ghcjs/issues/665
14-
constraints: primitive <0.6.4
15-
16-
-- ghcjs-base wants old aeson
17-
allow-newer: ghcjs-base:aeson
18-
19-
-- https://github.com/nomeata/hackage-ghcjs-overlay
20-
repository ghcjs-overlay
21-
url: http://hackage-ghcjs-overlay.nomeata.de/
22-
secure: True
23-
root-keys:
24-
key-threshold: 0

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ packages:
3333

3434
tests: True
3535
optimization: False
36+
reorder-goals: True
3637

3738
allow-newer:
3839
servant-js:base

doc/cookbook/using-free-client/UsingFreeClient.lhs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ test = case getSquare 42 of
9999
putStrLn $ "ERROR: got pure result: " ++ show n
100100
Free (Throw err) ->
101101
putStrLn $ "ERROR: got error right away: " ++ show err
102-
Free (StreamingRequest _req _k) ->
103-
putStrLn $ "ERROR: need to do streaming request" -- TODO: no Show Req :(
104102
```
105103
106104
We are interested in `RunRequest`, that's what client should block on:

servant-client-core/servant-client-core.cabal

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ library
3636
Servant.Client.Free
3737
Servant.Client.Generic
3838
Servant.Client.Core.Reexport
39-
Servant.Client.Core.Internal.Auth
40-
Servant.Client.Core.Internal.BaseUrl
41-
Servant.Client.Core.Internal.BasicAuth
42-
Servant.Client.Core.Internal.ClientError
43-
Servant.Client.Core.Internal.ClientF
44-
Servant.Client.Core.Internal.Generic
45-
Servant.Client.Core.Internal.HasClient
46-
Servant.Client.Core.Internal.Request
47-
Servant.Client.Core.Internal.Response
48-
Servant.Client.Core.Internal.RunClient
39+
Servant.Client.Core.Auth
40+
Servant.Client.Core.BaseUrl
41+
Servant.Client.Core.BasicAuth
42+
Servant.Client.Core.ClientError
43+
Servant.Client.Core.HasClient
44+
Servant.Client.Core.Request
45+
Servant.Client.Core.Response
46+
Servant.Client.Core.RunClient
47+
48+
other-modules:
49+
Servant.Client.Core.Internal
4950

5051
-- Bundled with GHC: Lower bound to not force re-installs
5152
-- text and mtl are bundled starting with GHC-8.4
@@ -76,7 +77,6 @@ library
7677
, base64-bytestring >= 1.0.0.1 && < 1.1
7778
, exceptions >= 0.10.0 && < 0.11
7879
, free >= 5.1 && < 5.2
79-
, generics-sop >= 0.4.0.1 && < 0.5
8080
, http-media >= 0.7.1.3 && < 0.8
8181
, http-types >= 0.12.2 && < 0.13
8282
, network-uri >= 2.6.1.0 && < 2.7

servant-client-core/src/Servant/Client/Core.hs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ module Servant.Client.Core
3232
, AuthClientData
3333

3434
-- * Generic Client
35-
, ClientLike(..)
36-
, genericMkClientL
37-
, genericMkClientP
3835
, ServantError(..)
3936
, EmptyClient(..)
4037

41-
4238
-- * Response
4339
, Response
4440
, ResponseF (..)
4541
, RunClient(..)
46-
, module Servant.Client.Core.Internal.BaseUrl
42+
-- * BaseUrl
43+
, BaseUrl (..)
44+
, Scheme (..)
45+
, showBaseUrl
46+
, parseBaseUrl
47+
, InvalidBaseUrlException (..)
48+
4749
-- ** Streaming
4850
, RunStreamingClient(..)
4951
, StreamingResponse
@@ -56,14 +58,13 @@ module Servant.Client.Core
5658
, setRequestBodyLBS
5759
, setRequestBody
5860
) where
59-
import Servant.Client.Core.Internal.Auth
60-
import Servant.Client.Core.Internal.BaseUrl
61-
(BaseUrl (..), InvalidBaseUrlException, Scheme (..),
61+
import Servant.Client.Core.Auth
62+
import Servant.Client.Core.BaseUrl
63+
(BaseUrl (..), InvalidBaseUrlException (..), Scheme (..),
6264
parseBaseUrl, showBaseUrl)
63-
import Servant.Client.Core.Internal.BasicAuth
64-
import Servant.Client.Core.Internal.Generic
65-
import Servant.Client.Core.Internal.HasClient
66-
import Servant.Client.Core.Internal.Request
67-
import Servant.Client.Core.Internal.Response
68-
import Servant.Client.Core.Internal.ClientError
69-
import Servant.Client.Core.Internal.RunClient
65+
import Servant.Client.Core.BasicAuth
66+
import Servant.Client.Core.ClientError
67+
import Servant.Client.Core.HasClient
68+
import Servant.Client.Core.Request
69+
import Servant.Client.Core.Response
70+
import Servant.Client.Core.RunClient

servant-client-core/src/Servant/Client/Core/Internal/Auth.hs renamed to servant-client-core/src/Servant/Client/Core/Auth.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
-- | Authentication for clients
66

7-
module Servant.Client.Core.Internal.Auth where
7+
module Servant.Client.Core.Auth (
8+
AuthClientData,
9+
AuthenticatedRequest (..),
10+
mkAuthenticatedRequest,
11+
) where
812

9-
import Servant.Client.Core.Internal.Request
13+
import Servant.Client.Core.Request
1014
(Request)
1115

1216
-- | For a resource protected by authentication (e.g. AuthProtect), we need

servant-client-core/src/Servant/Client/Core/Internal/BaseUrl.hs renamed to servant-client-core/src/Servant/Client/Core/BaseUrl.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE DeriveLift #-}
44
{-# LANGUAGE ViewPatterns #-}
5-
module Servant.Client.Core.Internal.BaseUrl where
5+
module Servant.Client.Core.BaseUrl (
6+
BaseUrl (..),
7+
Scheme (..),
8+
showBaseUrl,
9+
parseBaseUrl,
10+
InvalidBaseUrlException (..),
11+
) where
612

713
import Control.DeepSeq
814
(NFData (..))

0 commit comments

Comments
 (0)