git.iko.soy/typeable/servant
on master help sign in
Merge pull request #818 from LumiGuide/feat-client-ghcjs

servant-client-ghcjs

commit13986429ef528ecd67528689d46b707c89e56dee authorOleg Grenrus <oleg.grenrus@iki.fi> dateSun 3 Dec 2017, 17:19 (9 years ago) parentc1371dde3a11db
8 files changed+573
servant-client-ghcjs/CHANGELOG.md+3 servant-client-ghcjs/LICENSE+30 servant-client-ghcjs/README.md+175 servant-client-ghcjs/Setup.hs+2 servant-client-ghcjs/servant-client-ghcjs.cabal+54 servant-client-ghcjs/src/Servant/Client/Ghcjs.hs+14 servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs+290 servant-client-ghcjs/tinc.yaml+5
servant-client-ghcjs/CHANGELOG.mdnew file+3
@@ -0,0 +1,3 @@
1+0.11
2+----
3+Initial
servant-client-ghcjs/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2014-2016, Zalora South East Asia Pte Ltd, Servant Contributors
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Zalora South East Asia Pte Ltd nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
servant-client-ghcjs/README.mdnew file+175
@@ -0,0 +1,175 @@
1+# servant-client-ghcjs
2+
3+Type safe querying of servant APIs from the browser.
4+
5+`servant-client-ghcjs` is much like `servant-client`, as both packages allow you to generate functions that query the endpoints of your servant API. Both packages should feel the same in usage. The big difference lies in how they perform the actual requests. `servant-client` (indirectly) uses your operating system's socket mechanisms, whereas `servant-client-ghcjs` uses your browser's [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) mechanisms to send requests.
6+
7+This guide assumes knowledge of servant. Reading its [documentation](http://haskell-servant.readthedocs.io) is recommended if you're new to the subject.
8+
9+## Using servant-client-ghcjs
10+`servant-client-ghcjs` should feel familiar if you've worked with `servant-client`.
11+
12+Take the following API (taken from the [Querying an API](http://haskell-servant.readthedocs.io/en/stable/tutorial/Client.html) section in the servant documentation)
13+
14+```haskell
15+{-# LANGUAGE DataKinds #-}
16+{-# LANGUAGE DeriveGeneric #-}
17+{-# LANGUAGE TypeOperators #-}
18+
19+module Main where
20+
21+import Data.Aeson
22+import Data.Proxy
23+import GHC.Generics
24+import Servant.API -- From the 'servant' package, to define the API itself
25+import Servant.Client.Ghcjs -- To generate client functions
26+
27+type API =
28+ "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
29+ :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
30+ :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email
31+
32+
33+-- Data types used in the API
34+
35+data Position = Position
36+ { xCoord :: Int
37+ , yCoord :: Int
38+ } deriving (Show, Generic)
39+
40+instance FromJSON Position
41+
42+newtype HelloMessage = HelloMessage { msg :: String }
43+ deriving (Show, Generic)
44+
45+instance FromJSON HelloMessage
46+
47+data ClientInfo = ClientInfo
48+ { clientName :: String
49+ , clientEmail :: String
50+ , clientAge :: Int
51+ , clientInterestedIn :: [String]
52+ } deriving Generic
53+
54+instance ToJSON ClientInfo
55+
56+data Email = Email
57+ { from :: String
58+ , to :: String
59+ , subject :: String
60+ , body :: String
61+ } deriving (Show, Generic)
62+
63+instance FromJSON Email
64+```
65+
66+Client functions are generated with the `client` function, like with `servant-client`:
67+
68+```haskell
69+position :: Int
70+ -> Int
71+ -> ClientM Position
72+
73+hello :: Maybe String
74+ -> ClientM HelloMessage
75+
76+marketing :: ClientInfo
77+ -> ClientM Email
78+
79+api :: Proxy API
80+api = Proxy
81+
82+position :<|> hello :<|> marketing = client api
83+```
84+
85+To run these requests, they only need to be given to `runClientM`. The type of which is as follows:
86+
87+```haskell
88+runClientM :: ClientM a -> IO (Either ServantError a)
89+```
90+
91+The requests can then be run as follows:
92+
93+```haskell
94+main :: IO ()
95+main = do
96+ ePos <- runClientM $ position 10 20
97+ print ePos
98+
99+ eHelloMessage <- runClientM $ hello (Just "Servant")
100+ print eHelloMessage
101+
102+ eEmail <- runClientM $ marketing ClientInfo
103+ { clientName = "Servant"
104+ , clientEmail = "servant@example.com"
105+ , clientAge = 3
106+ , clientInterestedIn = ["servant", "haskell", "type safety", "web apps"]
107+ }
108+ print eEmail
109+```
110+
111+`runClientM` requires no URL, as it assumes that all requests are meant for the server that served the web page on which the code is being run. It is however possible to call REST APIs from other locations with [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) using `runClientMOrigin`:
112+
113+```haskell
114+runClientMOrigin :: ClientM a -> ClientEnv -> IO (Either ServantError a)
115+```
116+
117+Where `ClientEnv` holds a `BaseURL` that tells servant where to send the request to.
118+
119+# Common client functions
120+Specifically in big applications it can be desirable to have client functions that work for both `servant-client` *and* `servant-client-ghcjs`. Luckily, the common bits of those two packages live in a parent package, called `servant-client-core`. This package holds the tools to create generic client functions. Generating clients this way is a bit different, though, as the client functions need to be generic in the monad `m` that runs the actual requests.
121+
122+In the example below, the client functions are put in a data type called `APIClient`, which has `m` as a type parameter. The lowercase `apiClient` constructs this data type, demanding that `m` is indeed a monad that can run requests.
123+
124+```haskell
125+{-# LANGUAGE FlexibleContexts #-}
126+{-# LANGUAGE RecordWildCards #-}
127+{-# LANGUAGE ScopedTypeVariables #-}
128+{-# LANGUAGE TypeApplications #-}
129+
130+...
131+import Servant.Client.Core -- From the 'servant-client-core' package
132+
133+...
134+
135+data APIClient m = APIClient
136+ { position :: Int -> Int -> m Position
137+ , hello :: Maybe String -> m HelloMessage
138+ , marketing :: ClientInfo -> m Email
139+ }
140+
141+apiClient
142+ :: forall m
143+ . RunClient m
144+ => APIClient m
145+apiClient = APIClient { .. }
146+ where
147+ position
148+ :<|> hello
149+ :<|> marketing = Proxy @API `clientIn` Proxy @m
150+```
151+
152+The call site changes slightly too, as the functions now need to be taken from `apiClient`:
153+
154+```haskell
155+import Servant.Client.Ghcjs
156+
157+main :: IO ()
158+main = do
159+ ePos <- runClientM $ position apiClient 10 20
160+ print ePos
161+```
162+
163+Here's how the requests would be performed using the regular `servant-client` package:
164+
165+```haskell
166+import Servant.Client
167+import Network.HTTP.Client ( newManager, defaultManagerSettings )
168+
169+main :: IO ()
170+main = do
171+ mgr <- newManager defaultManagerSettings
172+ let clientBaseUrl = BaseUrl Http "www.example.com" 80 ""
173+ ePos <- runClientM (position apiClient 10 20) $ ClientEnv mgr clientBaseUrl
174+ print ePos
175+```
servant-client-ghcjs/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
servant-client-ghcjs/servant-client-ghcjs.cabalnew file+54
@@ -0,0 +1,54 @@
1+name: servant-client-ghcjs
2+version: 0.11
3+synopsis: automatical derivation of querying functions for servant webservices for ghcjs
4+description:
5+ This library lets you automatically derive Haskell functions that
6+ let you query each endpoint of a <http://hackage.haskell.org/package/servant servant> webservice.
7+ .
8+ See <http://haskell-servant.readthedocs.org/en/stable/tutorial/Client.html the client section of the tutorial>.
9+ .
10+ <https://github.com/haskell-servant/servant/blob/master/servant-client/CHANGELOG.md CHANGELOG>
11+license: BSD3
12+license-file: LICENSE
13+author: Servant Contributors
14+maintainer: haskell-servant-maintainers@googlegroups.com
15+copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2017 Servant Contributors
16+category: Servant, Web
17+build-type: Simple
18+cabal-version: >=1.10
19+tested-with: GHC >= 7.8
20+homepage: http://haskell-servant.readthedocs.org/
21+Bug-reports: http://github.com/haskell-servant/servant/issues
22+extra-source-files:
23+ CHANGELOG.md
24+ README.md
25+source-repository head
26+ type: git
27+ location: http://github.com/haskell-servant/servant.git
28+
29+library
30+ exposed-modules:
31+ Servant.Client.Ghcjs
32+ Servant.Client.Internal.XhrClient
33+ build-depends:
34+ base >= 4.7 && < 4.11
35+ , bytestring >= 0.10 && < 0.11
36+ , case-insensitive >= 1.2.0.0 && < 1.3.0.0
37+ , containers >= 0.5 && < 0.6
38+ , exceptions >= 0.8 && < 0.9
39+ , ghcjs-base >= 0.2.0.0 && < 0.3.0.0
40+ , ghcjs-prim >= 0.1.0.0 && < 0.2.0.0
41+ , http-media >= 0.6.2 && < 0.8
42+ , http-types >= 0.8.6 && < 0.10
43+ , monad-control >= 1.0.0.4 && < 1.1
44+ , mtl >= 2.1 && < 2.3
45+ , semigroupoids >= 4.3 && < 5.3
46+ , servant-client-core == 0.11.*
47+ , string-conversions >= 0.3 && < 0.5
48+ , transformers >= 0.3 && < 0.6
49+ , transformers-base >= 0.4.4 && < 0.5
50+ hs-source-dirs: src
51+ default-language: Haskell2010
52+ ghc-options: -Wall
53+ if impl(ghc >= 8.0)
54+ ghc-options: -Wno-redundant-constraints
servant-client-ghcjs/src/Servant/Client/Ghcjs.hsnew file+14
@@ -0,0 +1,14 @@
1+-- | This module provides 'client' which can automatically generate
2+-- querying functions for each endpoint just from the type representing your
3+-- API.
4+module Servant.Client.Ghcjs
5+ (
6+ client
7+ , ClientM
8+ , runClientM
9+ , ClientEnv(..)
10+ , module Servant.Client.Core.Reexport
11+ ) where
12+
13+import Servant.Client.Internal.XhrClient
14+import Servant.Client.Core.Reexport
servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hsnew file+290
@@ -0,0 +1,290 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6+{-# LANGUAGE MultiParamTypeClasses #-}
7+{-# LANGUAGE OverloadedStrings #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
9+{-# LANGUAGE TypeFamilies #-}
10+{-# LANGUAGE ViewPatterns #-}
11+
12+
13+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
14+
15+module Servant.Client.Internal.XhrClient where
16+
17+import Control.Arrow
18+import Data.ByteString.Builder (toLazyByteString)
19+import Control.Concurrent
20+import Control.Exception
21+import Control.Monad
22+import Control.Monad.Base (MonadBase (..))
23+import Control.Monad.Catch (MonadCatch, MonadThrow)
24+import Control.Monad.Error.Class (MonadError (..))
25+import Control.Monad.Reader
26+import Control.Monad.Trans.Control (MonadBaseControl (..))
27+import Control.Monad.Trans.Except
28+import qualified Data.ByteString.Char8 as BS
29+import Data.CaseInsensitive
30+import Data.Char
31+import Data.Foldable (toList)
32+import Data.Functor.Alt (Alt (..))
33+import Data.Proxy (Proxy (..))
34+import qualified Data.Sequence as Seq
35+import Data.String.Conversions
36+import Foreign.StablePtr
37+import GHC.Generics
38+import GHCJS.Foreign.Callback
39+import GHCJS.Prim
40+import GHCJS.Types
41+import JavaScript.Web.Location
42+import Network.HTTP.Types
43+import Network.HTTP.Media (renderHeader)
44+import Servant.Client.Core
45+
46+newtype JSXMLHttpRequest = JSXMLHttpRequest JSVal
47+
48+newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
49+
50+newtype ClientEnv
51+ = ClientEnv
52+ { baseUrl :: BaseUrl }
53+ deriving (Eq, Show)
54+
55+client :: HasClient ClientM api => Proxy api -> Client ClientM api
56+client api = api `clientIn` (Proxy :: Proxy ClientM)
57+
58+newtype ClientM a = ClientM
59+ { runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO) a }
60+ deriving ( Functor, Applicative, Monad, MonadIO, Generic
61+ , MonadReader ClientEnv, MonadError ServantError, MonadThrow
62+ , MonadCatch)
63+
64+instance MonadBase IO ClientM where
65+ liftBase = ClientM . liftBase
66+
67+instance MonadBaseControl IO ClientM where
68+ type StM ClientM a = Either ServantError a
69+
70+ liftBaseWith f = ClientM (liftBaseWith (\g -> f (g . runClientM')))
71+
72+ restoreM st = ClientM (restoreM st)
73+
74+-- | Try clients in order, last error is preserved.
75+instance Alt ClientM where
76+ a <!> b = a `catchError` const b
77+
78+instance RunClient ClientM where
79+ runRequest = performRequest
80+ throwServantError = throwError
81+ catchServantError = catchError
82+
83+instance ClientLike (ClientM a) (ClientM a) where
84+ mkClient = id
85+
86+runClientMOrigin :: ClientM a -> ClientEnv -> IO (Either ServantError a)
87+runClientMOrigin cm env = runExceptT $ flip runReaderT env $ runClientM' cm
88+
89+runClientM :: ClientM a -> IO (Either ServantError a)
90+runClientM m = do
91+ curLoc <- getWindowLocation
92+
93+ jsStr_protocol <- getProtocol curLoc
94+ jsStr_port <- getPort curLoc
95+ jsStr_hostname <- getHostname curLoc
96+
97+ let protocol
98+ | jsStr_protocol == "https:" = Https
99+ | otherwise = Http
100+
101+ portStr :: String
102+ portStr = fromJSString $ jsval jsStr_port
103+
104+ port :: Int
105+ port | null portStr = case protocol of
106+ Http -> 80
107+ Https -> 443
108+ | otherwise = read portStr
109+
110+ hostname :: String
111+ hostname = fromJSString $ jsval jsStr_hostname
112+
113+ runClientMOrigin m (ClientEnv (BaseUrl protocol hostname port ""))
114+
115+performRequest :: Request -> ClientM Response
116+performRequest req = do
117+ xhr <- liftIO initXhr
118+ burl <- asks baseUrl
119+ liftIO $ performXhr xhr burl req
120+ resp <- toResponse xhr
121+
122+ let status = statusCode (responseStatusCode resp)
123+ unless (status >= 200 && status < 300) $
124+ throwError $ FailureResponse resp
125+
126+ pure resp
127+
128+-- * initialization
129+
130+initXhr :: IO JSXMLHttpRequest
131+initXhr = do
132+ lib <- requireXMLHttpRequestClass
133+ newXMLHttpRequest lib
134+
135+foreign import javascript unsafe
136+ -- branching between node (for testing) and browsers
137+ "(function () {if (typeof require !== 'undefined') { return require('xhr2'); } else { return XMLHttpRequest; };})()"
138+ requireXMLHttpRequestClass :: IO JSXMLHttpRequestClass
139+
140+foreign import javascript unsafe "new $1()"
141+ newXMLHttpRequest :: JSXMLHttpRequestClass -> IO JSXMLHttpRequest
142+
143+-- * performing requests
144+-- Performs the xhr and blocks until the response was received
145+performXhr :: JSXMLHttpRequest -> BaseUrl -> Request -> IO ()
146+performXhr xhr burl request = do
147+
148+ waiter <- newEmptyMVar
149+
150+ bracket (acquire waiter) releaseCallback $ \_callback -> do
151+ t <- myThreadId
152+ s <- newStablePtr t
153+
154+ openXhr xhr (cs $ requestMethod request) (toUrl burl request) True
155+ setHeaders xhr request
156+ sendXhr xhr (toBody request)
157+ takeMVar waiter
158+
159+ freeStablePtr s
160+ where
161+ acquire waiter = onReadyStateChange xhr $ do
162+ state <- readyState xhr
163+ case state of
164+ -- onReadyStateChange's callback can fire state 4
165+ -- (which means "request finished and response is ready")
166+ -- multiple times. By using tryPutMVar, only the first time
167+ -- state 4 is fired will cause an MVar to be put. Subsequent
168+ -- fires are ignored.
169+ 4 -> void $ tryPutMVar waiter ()
170+ _ -> return ()
171+
172+onReadyStateChange :: JSXMLHttpRequest -> IO () -> IO (Callback (IO ()))
173+onReadyStateChange xhr action = do
174+ callback <- asyncCallback action
175+ js_onReadyStateChange xhr callback
176+ return callback
177+foreign import javascript safe "$1.onreadystatechange = $2;"
178+ js_onReadyStateChange :: JSXMLHttpRequest -> Callback (IO ()) -> IO ()
179+
180+foreign import javascript unsafe "$1.readyState"
181+ readyState :: JSXMLHttpRequest -> IO Int
182+
183+openXhr :: JSXMLHttpRequest -> String -> String -> Bool -> IO ()
184+openXhr xhr method url =
185+ js_openXhr xhr (toJSString method) (toJSString url)
186+foreign import javascript unsafe "$1.open($2, $3, $4)"
187+ js_openXhr :: JSXMLHttpRequest -> JSVal -> JSVal -> Bool -> IO ()
188+
189+toUrl :: BaseUrl -> Request -> String
190+toUrl burl request =
191+ let pathS = cs $ toLazyByteString $ requestPath request
192+ queryS =
193+ cs $
194+ renderQuery True $
195+ toList $
196+ requestQueryString request
197+ in showBaseUrl burl ++ pathS ++ queryS
198+
199+setHeaders :: JSXMLHttpRequest -> Request -> IO ()
200+setHeaders xhr request = do
201+ forM_ (toList $ requestAccept request) $ \mediaType ->
202+ js_setRequestHeader
203+ xhr
204+ (toJSString "Accept")
205+ (toJSString $ cs $ renderHeader mediaType)
206+
207+ forM_ (requestBody request) $ \(_, mediaType) ->
208+ js_setRequestHeader
209+ xhr
210+ (toJSString "Content-Type")
211+ (toJSString $ cs $ renderHeader mediaType)
212+
213+ forM_ (toList $ requestHeaders request) $ \(key, value) ->
214+ js_setRequestHeader xhr (toJSString $ cs $ original key) (toJSString $ cs value)
215+
216+foreign import javascript unsafe "$1.setRequestHeader($2, $3)"
217+ js_setRequestHeader :: JSXMLHttpRequest -> JSVal -> JSVal -> IO ()
218+
219+sendXhr :: JSXMLHttpRequest -> Maybe String -> IO ()
220+sendXhr xhr Nothing = js_sendXhr xhr
221+sendXhr xhr (Just body) =
222+ js_sendXhrWithBody xhr (toJSString body)
223+
224+foreign import javascript unsafe "$1.send()"
225+ js_sendXhr :: JSXMLHttpRequest -> IO ()
226+
227+foreign import javascript unsafe "$1.send($2)"
228+ js_sendXhrWithBody :: JSXMLHttpRequest -> JSVal -> IO ()
229+
230+toBody :: Request -> Maybe String
231+toBody request = case requestBody request of
232+ Nothing -> Nothing
233+ Just (RequestBodyLBS "", _) -> Nothing
234+ Just (RequestBodyLBS x, _) -> Just $ cs x
235+
236+-- * inspecting the xhr response
237+
238+-- This function is only supposed to handle 'ConnectionError's. Other
239+-- 'ServantError's are created in Servant.Client.Req.
240+toResponse :: JSXMLHttpRequest -> ClientM Response
241+toResponse xhr = do
242+ status <- liftIO $ getStatus xhr
243+ case status of
244+ 0 -> throwError $ ConnectionError "connection error"
245+ _ -> liftIO $ do
246+ statusText <- cs <$> getStatusText xhr
247+ headers <- parseHeaders <$> getAllResponseHeaders xhr
248+ responseText <- cs <$> getResponseText xhr
249+ pure Response
250+ { responseStatusCode = mkStatus status statusText
251+ , responseBody = responseText
252+ , responseHeaders = Seq.fromList headers
253+ , responseHttpVersion = http11 -- this is made up
254+ }
255+
256+foreign import javascript unsafe "$1.status"
257+ getStatus :: JSXMLHttpRequest -> IO Int
258+
259+getStatusText :: JSXMLHttpRequest -> IO String
260+getStatusText = fmap fromJSString . js_statusText
261+foreign import javascript unsafe "$1.statusText"
262+ js_statusText :: JSXMLHttpRequest -> IO JSVal
263+
264+getAllResponseHeaders :: JSXMLHttpRequest -> IO String
265+getAllResponseHeaders xhr =
266+ fromJSString <$> js_getAllResponseHeaders xhr
267+foreign import javascript unsafe "$1.getAllResponseHeaders()"
268+ js_getAllResponseHeaders :: JSXMLHttpRequest -> IO JSVal
269+
270+getResponseText :: JSXMLHttpRequest -> IO String
271+getResponseText xhr = fromJSString <$> js_responseText xhr
272+foreign import javascript unsafe "$1.responseText"
273+ js_responseText :: JSXMLHttpRequest -> IO JSVal
274+
275+parseHeaders :: String -> ResponseHeaders
276+parseHeaders s =
277+ (first mk . first strip . second strip . parseHeader) <$>
278+ splitOn "\r\n" (cs s)
279+ where
280+ parseHeader :: BS.ByteString -> (BS.ByteString, BS.ByteString)
281+ parseHeader h = case BS.breakSubstring ":" (cs h) of
282+ (key, BS.drop 1 -> value) -> (key, value)
283+
284+ splitOn :: BS.ByteString -> BS.ByteString -> [BS.ByteString]
285+ splitOn separator input = case BS.breakSubstring separator input of
286+ (prefix, "") -> [prefix]
287+ (prefix, rest) -> prefix : splitOn separator (BS.drop (BS.length separator) rest)
288+
289+ strip :: BS.ByteString -> BS.ByteString
290+ strip = BS.dropWhile isSpace . BS.reverse . BS.dropWhile isSpace . BS.reverse
servant-client-ghcjs/tinc.yamlnew file+5
@@ -0,0 +1,5 @@
1+dependencies:
2+ - name: servant
3+ path: ../servant
4+ - name: servant-server
5+ path: ../servant-server