@@ -39,36 +39,34 @@ module Servant.Reflex
3939
4040------------------------------------------------------------------------------
4141import Control.Applicative
42−import qualified Data.CaseInsensitive as CI
43−import Data.Functor.Identity
44−import qualified Data.Map as Map
4542import Data.Monoid ((<>))
46−import Data.Proxy (Proxy (..))
4743import qualified Data.Set as Set
44+import qualified Data.Text.Encoding as E
45+import Data.CaseInsensitive (mk)
46+import Data.Functor.Identity
47+import Data.Proxy (Proxy (..))
48+import qualified Data.Map as Map
4849import Data.Text (Text)
4950import qualified Data.Text as T
50−import qualified Data.Text.Encoding as E
5151import GHC.Exts (Constraint)
5252import GHC.TypeLits (KnownSymbol, symbolVal)
53−import Servant.API ((:<|>) (..), (:>), BasicAuth,
54− BasicAuthData, BuildHeadersTo (..),
55− Capture, Header, Headers (..),
56− HttpVersion, IsSecure,
57− MimeRender (..), MimeUnrender,
58− NoContent, QueryFlag, QueryParam',
59− QueryParams, Raw, ReflectMethod (..),
53+import Servant.API ((:<|>)(..),(:>), BasicAuth,
54+ BasicAuthData, BuildHeadersTo(..),
55+ Capture, contentType, Header,
56+ Headers(..), HttpVersion, IsSecure,
57+ MimeRender(..), MimeUnrender,
58+ NoContent, QueryFlag, QueryParam,
59+ QueryParams, Raw, ReflectMethod(..),
6060 RemoteHost, ReqBody,
61− ToHttpApiData (..), Vault, Verb,
62− contentType)
63−import Servant.API.Description (Summary)
61+ ToHttpApiData(..), Vault, Verb)
6462import qualified Servant.Auth as Auth
6563
6664import Reflex.Dom.Core (Dynamic, Event, Reflex,
67− XhrRequest (..), XhrResponse (..),
68− XhrResponseHeaders (..),
69− attachPromptlyDynWith, constDyn, ffor,
70− fmapMaybe, leftmost,
71− performRequestsAsync)
65+ XhrRequest(..),
66+ XhrResponseHeaders(..),
67+ XhrResponse(..), attachPromptlyDynWith, constDyn, ffor, fmapMaybe,
68+ leftmost, performRequestsAsync,
69+ )
7270------------------------------------------------------------------------------
7371import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
7472 showBaseUrl,
@@ -103,7 +101,7 @@ import Servant.Common.Req (ClientOptions(..),
103101-- >
104102-- > getAllBooks :: Event t l -> m (Event t (l, ReqResult [Book]))
105103-- > postNewBook :: Dynamic t (Maybe Book) -> Event t l
106−-- > -> m (Event t (l, ReqResult Book)))
104+-- -> m (Event t (l, ReqResult Book)))
107105-- > (getAllBooks :<|> postNewBook) = client myApi host
108106-- > where host = constDyn $ BaseUrl Http "localhost" 8080
109107client
@@ -228,26 +226,22 @@ instance {-# OVERLAPPING #-}
228226
229227toHeaders :: BuildHeadersTo ls => ReqResult tag a -> ReqResult tag (Headers ls a)
230228toHeaders r =
231− let hdrs = maybe []
232− (\xhr -> fmap (\(h,v) -> (CI.map E.encodeUtf8 h, E.encodeUtf8 v))
229+ let toBS = E.encodeUtf8
230+ hdrs = maybe []
231+ (\xhr -> fmap (\(h,v) -> (mk (toBS h), toBS v))
233232 (Map.toList $ _xhrResponse_headers xhr))
234233 (response r)
235234 in ffor r $ \a -> Headers {getResponse = a ,getHeadersHList = buildHeadersTo hdrs}
236235
237−
238236class BuildHeaderKeysTo hs where
239− buildHeaderKeysTo :: Proxy hs -> [CI.CI T.Text]
237+ buildHeaderKeysTo :: Proxy hs -> [T.Text]
240238
241239instance {-# OVERLAPPABLE #-} BuildHeaderKeysTo '[]
242240 where buildHeaderKeysTo _ = []
243241
244242instance {-# OVERLAPPABLE #-} (BuildHeaderKeysTo xs, KnownSymbol h)
245243 => BuildHeaderKeysTo ((Header h v) ': xs) where
246− buildHeaderKeysTo _ =
247− let
248− thisKey = CI.mk $ T.pack (symbolVal (Proxy :: Proxy h))
249− in thisKey : buildHeaderKeysTo (Proxy :: Proxy xs)
250−
244+ buildHeaderKeysTo _ = T.pack (symbolVal (Proxy :: Proxy h)) : buildHeaderKeysTo (Proxy :: Proxy xs)
251245
252246-- HEADERS Verb (Content) --
253247-- Headers combinator not treated in fully general case,
@@ -329,19 +323,6 @@ instance HasClient t m sublayout tag
329323 clientWithRouteAndResultHandler Proxy =
330324 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
331325
332−-- | Using a 'Summary' combinator in your API doesn't affect the client
333−-- functions.
334−instance (HasClient t m sublayout tag, KnownSymbol sym)
335− => HasClient t m (Summary sym :> sublayout) tag where
336−
337− type Client t m (Summary sym :> sublayout) tag =
338− Client t m sublayout tag
339−
340− clientWithRouteAndResultHandler Proxy =
341− clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
342−
343−
344−
345326
346327-- | If you use a 'QueryParam' in one of your endpoints in your API,
347328-- the corresponding querying function will automatically take
@@ -370,9 +351,9 @@ instance (HasClient t m sublayout tag, KnownSymbol sym)
370351-- > -- 'getBooksBy Nothing' for all books
371352-- > -- 'getBooksBy (Just "Isaac Asimov")' to get all books by Isaac Asimov
372353instance (KnownSymbol sym, ToHttpApiData a, HasClient t m sublayout tag, Reflex t)
373− => HasClient t m (QueryParam' mods sym a :> sublayout) tag where
354+ => HasClient t m (QueryParam sym a :> sublayout) tag where
374355
375− type Client t m (QueryParam' mods sym a :> sublayout) tag =
356+ type Client t m (QueryParam sym a :> sublayout) tag =
376357 Dynamic t (QParam a) -> Client t m sublayout tag
377358
378359 -- if mparam = Nothing, we don't add it to the query string
@@ -622,3 +603,4 @@ type family HasCookieAuth xs :: Constraint where
622603 HasCookieAuth '[] = CookieAuthNotEnabled
623604
624605class CookieAuthNotEnabled
606+