git.iko.soy/typeable/servant
on master help sign in
Add mods to StreamBody
commit3001ed799053524495026bb236c8e76001c250e8 authorOleg Grenrus <oleg.grenrus@iki.fi> dateFri 9 Nov 2018, 21:49 (8 years ago) parentbbf1967
9 files changed+35−32
servant-client-core/src/Servant/Client/Core/Internal/HasClient.hs+3−3 servant-docs/src/Servant/Docs/Internal.hs+1−1 servant-foreign/src/Servant/Foreign/Internal.hs+2−2 servant-server/src/Servant/Server/Internal.hs+3−3 servant-server/test/Servant/ServerSpec.hs+11−9 servant/src/Servant/API.hs+7−7 servant/src/Servant/API/Stream.hs+4−3 servant/src/Servant/Links.hs+3−3 servant/src/Servant/Test/ComprehensiveAPI.hs+1−1
servant-client-core/src/Servant/Client/Core/Internal/HasClient.hs+3−3
@@ -40,7 +40,7 @@ import Servant.API
4040 Headers (..), HttpVersion, IsSecure, MimeRender (mimeRender),
4141 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
4242 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
43− ReqBody', SBoolI, Stream, StreamBody, Summary, ToHttpApiData,
43+ ReqBody', SBoolI, Stream, StreamBody', Summary, ToHttpApiData,
4444 Vault, Verb, WithNamedContext, contentType, getHeadersHList,
4545 getResponse, toQueryParam, toUrlPiece)
4646import Servant.API.ContentTypes
@@ -539,10 +539,10 @@ instance (MimeRender ct a, HasClient m api)
539539
540540instance
541541 ( HasClient m api
542− ) => HasClient m (StreamBody framing ctype a :> api)
542+ ) => HasClient m (StreamBody' mods framing ctype a :> api)
543543 where
544544
545− type Client m (StreamBody framing ctype a :> api) = a -> Client m api
545+ type Client m (StreamBody' mods framing ctype a :> api) = a -> Client m api
546546
547547 hoistClientMonad pm _ f cl = \a ->
548548 hoistClientMonad pm (Proxy :: Proxy api) f (cl a)
servant-docs/src/Servant/Docs/Internal.hs+1−1
@@ -980,7 +980,7 @@ instance (ToSample a, AllMimeRender (ct ': cts) a, HasDocs api)
980980 p = Proxy :: Proxy a
981981
982982-- | TODO: this instance is incomplete.
983−instance (HasDocs api, Accept ctype) => HasDocs (StreamBody framing ctype a :> api) where
983+instance (HasDocs api, Accept ctype) => HasDocs (StreamBody' mods framing ctype a :> api) where
984984 docsFor Proxy (endpoint, action) opts =
985985 docsFor subApiP (endpoint, action') opts
986986 where
servant-foreign/src/Servant/Foreign/Internal.hs+2−2
@@ -328,9 +328,9 @@ instance (Elem JSON list, HasForeignType lang ftype a, HasForeign lang ftype api
328328
329329instance
330330 ( HasForeign lang ftype api
331− ) => HasForeign lang ftype (StreamBody framing ctype a :> api)
331+ ) => HasForeign lang ftype (StreamBody' mods framing ctype a :> api)
332332 where
333− type Foreign ftype (StreamBody framing ctype a :> api) = Foreign ftype api
333+ type Foreign ftype (StreamBody' mods framing ctype a :> api) = Foreign ftype api
334334
335335 foreignFor _lang Proxy Proxy _req = error "HasForeign @StreamBody"
336336
servant-server/src/Servant/Server/Internal.hs+3−3
@@ -71,7 +71,7 @@ import Servant.API
7171 FramingUnrender (..), FromSourceIO (..), Header', If,
7272 IsSecure (..), QueryFlag, QueryParam', QueryParams, Raw,
7373 ReflectMethod (reflectMethod), RemoteHost, ReqBody',
74− SBool (..), SBoolI (..), SourceIO, Stream, StreamBody,
74+ SBool (..), SBoolI (..), SourceIO, Stream, StreamBody',
7575 Summary, ToSourceIO (..), Vault, Verb, WithNamedContext)
7676import Servant.API.ContentTypes
7777 (AcceptHeader (..), AllCTRender (..), AllCTUnrender (..),
@@ -610,9 +610,9 @@ instance ( AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods
610610instance
611611 ( FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk
612612 , HasServer api context
613− ) => HasServer (StreamBody framing ctype a :> api) context
613+ ) => HasServer (StreamBody' mods framing ctype a :> api) context
614614 where
615− type ServerT (StreamBody framing ctype a :> api) m = a -> ServerT api m
615+ type ServerT (StreamBody' mods framing ctype a :> api) m = a -> ServerT api m
616616
617617 hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s
618618
servant-server/test/Servant/ServerSpec.hs+11−9
@@ -12,24 +12,26 @@
1212
1313module Servant.ServerSpec where
1414
15+import Prelude ()
16+import Prelude.Compat
17+
1518import Control.Monad
1619 (forM_, unless, when)
1720import Control.Monad.Error.Class
1821 (MonadError (..))
1922import Data.Aeson
2023 (FromJSON, ToJSON, decode', encode)
21−import qualified Data.ByteString as BS
22−import qualified Data.ByteString.Base64 as Base64
24+import qualified Data.ByteString as BS
25+import qualified Data.ByteString.Base64 as Base64
2326import Data.Char
2427 (toUpper)
25−import Data.Monoid
2628import Data.Proxy
2729 (Proxy (Proxy))
2830import Data.String
2931 (fromString)
3032import Data.String.Conversions
3133 (cs)
32−import qualified Data.Text as T
34+import qualified Data.Text as T
3335import GHC.Generics
3436 (Generic)
3537import Network.HTTP.Types
@@ -42,25 +44,25 @@ import Network.Wai
4244import Network.Wai.Test
4345 (defaultRequest, request, runSession, simpleBody,
4446 simpleHeaders, simpleStatus)
45−import qualified Servant.Types.SourceT as S
4647import Servant.API
4748 ((:<|>) (..), (:>), AuthProtect, BasicAuth,
4849 BasicAuthData (BasicAuthData), Capture, CaptureAll, Delete,
4950 EmptyAPI, Get, Header, Headers, HttpVersion, IsSecure (..),
5051 JSON, NoContent (..), NoFraming, OctetStream, Patch,
5152 PlainText, Post, Put, QueryFlag, QueryParam, QueryParams, Raw,
52− RemoteHost, ReqBody, StdMethod (..), Stream,
53− SourceIO, Verb, addHeader)
54−import Servant.Test.ComprehensiveAPI
53+ RemoteHost, ReqBody, SourceIO, StdMethod (..), Stream, Verb,
54+ addHeader)
5555import Servant.Server
5656 (Context ((:.), EmptyContext), Handler, Server, Tagged (..),
5757 emptyServer, err401, err403, err404, serve, serveWithContext)
58+import Servant.Test.ComprehensiveAPI
59+import qualified Servant.Types.SourceT as S
5860import Test.Hspec
5961 (Spec, context, describe, it, shouldBe, shouldContain)
6062import Test.Hspec.Wai
6163 (get, liftIO, matchHeaders, matchStatus, shouldRespondWith,
6264 with, (<:>))
63−import qualified Test.Hspec.Wai as THW
65+import qualified Test.Hspec.Wai as THW
6466
6567import Servant.Server.Experimental.Auth
6668 (AuthHandler, AuthServerData, mkAuthHandler)
servant/src/Servant/API.hs+7−7
@@ -110,14 +110,14 @@ import Servant.API.ReqBody
110110 (ReqBody, ReqBody')
111111import Servant.API.ResponseHeaders
112112 (AddHeader, BuildHeadersTo (buildHeadersTo),
113− GetHeaders (getHeaders), HList (..), Headers (..),
114− ResponseHeader (..), addHeader, getHeadersHList, getResponse,
115− noHeader, HasResponseHeader, lookupResponseHeader)
113+ GetHeaders (getHeaders), HList (..), HasResponseHeader,
114+ Headers (..), ResponseHeader (..), addHeader, getHeadersHList,
115+ getResponse, lookupResponseHeader, noHeader)
116116import Servant.API.Stream
117− (FramingRender (..), FramingUnrender (..),
118− FromSourceIO (..), NetstringFraming, NewlineFraming,
119− NoFraming, SourceIO, Stream, StreamBody, SourceIO,
120− StreamGet, StreamPost, ToSourceIO (..))
117+ (FramingRender (..), FramingUnrender (..), FromSourceIO (..),
118+ NetstringFraming, NewlineFraming, NoFraming, SourceIO, Stream,
119+ StreamBody, StreamBody', StreamGet, StreamPost,
120+ ToSourceIO (..))
121121import Servant.API.Sub
122122 ((:>))
123123import Servant.API.Vault
servant/src/Servant/API/Stream.hs+4−3
@@ -17,6 +17,7 @@ module Servant.API.Stream (
1717 StreamGet,
1818 StreamPost,
1919 StreamBody,
20+ StreamBody',
2021 -- * Source
2122 --
2223 -- | 'SourceIO' are equivalent to some *source* in streaming libraries.
@@ -71,9 +72,9 @@ type StreamGet = Stream 'GET 200
7172type StreamPost = Stream 'POST 200
7273
7374-- | A stream request body.
74−--
75−-- TODO: add mods
76−data StreamBody (framing :: *) (contentType :: *) (a :: *)
75+type StreamBody = StreamBody' '[]
76+
77+data StreamBody' (mods :: [*]) (framing :: *) (contentType :: *) (a :: *)
7778 deriving (Typeable, Generic)
7879
7980-------------------------------------------------------------------------------
servant/src/Servant/Links.hs+3−3
@@ -170,7 +170,7 @@ import Servant.API.RemoteHost
170170import Servant.API.ReqBody
171171 (ReqBody')
172172import Servant.API.Stream
173− (Stream, StreamBody)
173+ (Stream, StreamBody')
174174import Servant.API.Sub
175175 (type (:>))
176176import Servant.API.TypeLevel
@@ -482,8 +482,8 @@ instance HasLink sub => HasLink (ReqBody' mods ct a :> sub) where
482482 type MkLink (ReqBody' mods ct a :> sub) r = MkLink sub r
483483 toLink toA _ = toLink toA (Proxy :: Proxy sub)
484484
485−instance HasLink sub => HasLink (StreamBody framing ct a :> sub) where
486− type MkLink (StreamBody framing ct a :> sub) r = MkLink sub r
485+instance HasLink sub => HasLink (StreamBody' mods framing ct a :> sub) where
486+ type MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub r
487487 toLink toA _ = toLink toA (Proxy :: Proxy sub)
488488
489489instance (ToHttpApiData v, HasLink sub)
servant/src/Servant/Test/ComprehensiveAPI.hs+1−1
@@ -22,7 +22,7 @@ type RawEndpoint =
2222 "raw" :> Raw
2323
2424type StreamingEndpoint =
25− "streaming" :> StreamBody NetstringFraming JSON (SourceT IO Int) :> Stream 'GET 200 NetstringFraming JSON (SourceT IO Int)
25+ "streaming" :> StreamBody' '[Description "netstring"] NetstringFraming JSON (SourceT IO Int) :> Stream 'GET 200 NetstringFraming JSON (SourceT IO Int)
2626
2727type EmptyEndpoint =
2828 "empty-api" :> EmptyAPI