git.iko.soy/typeable/servant
on master help sign in
Merge pull request #1077 from phadej/stream-body-mods
ce83e4bOleg Grenrus
servant-client-core/src/Servant/Client/Core/Internal/HasClient.hs+3−3
@@ -40,7 +40,7 @@ import Servant.API
40 Headers (..), HttpVersion, IsSecure, MimeRender (mimeRender),
40 Headers (..), HttpVersion, IsSecure, MimeRender (mimeRender),
41 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
41 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
42 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
42 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
43− ReqBody', SBoolI, Stream, StreamBody, Summary, ToHttpApiData,
43+ ReqBody', SBoolI, Stream, StreamBody', Summary, ToHttpApiData,
44 Vault, Verb, WithNamedContext, contentType, getHeadersHList,
44 Vault, Verb, WithNamedContext, contentType, getHeadersHList,
45 getResponse, toQueryParam, toUrlPiece)
45 getResponse, toQueryParam, toUrlPiece)
46import Servant.API.ContentTypes
46import Servant.API.ContentTypes
@@ -539,10 +539,10 @@ instance (MimeRender ct a, HasClient m api)
539
539
540instance
540instance
541 ( HasClient m api
541 ( HasClient m api
542− ) => HasClient m (StreamBody framing ctype a :> api)
542+ ) => HasClient m (StreamBody' mods framing ctype a :> api)
543 where
543 where
544
544
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
546
546
547 hoistClientMonad pm _ f cl = \a ->
547 hoistClientMonad pm _ f cl = \a ->
548 hoistClientMonad pm (Proxy :: Proxy api) f (cl a)
548 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)
980 p = Proxy :: Proxy a
980 p = Proxy :: Proxy a
981
981
982-- | TODO: this instance is incomplete.
982-- | 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
984 docsFor Proxy (endpoint, action) opts =
984 docsFor Proxy (endpoint, action) opts =
985 docsFor subApiP (endpoint, action') opts
985 docsFor subApiP (endpoint, action') opts
986 where
986 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
328
328
329instance
329instance
330 ( HasForeign lang ftype api
330 ( HasForeign lang ftype api
331− ) => HasForeign lang ftype (StreamBody framing ctype a :> api)
331+ ) => HasForeign lang ftype (StreamBody' mods framing ctype a :> api)
332 where
332 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
334
334
335 foreignFor _lang Proxy Proxy _req = error "HasForeign @StreamBody"
335 foreignFor _lang Proxy Proxy _req = error "HasForeign @StreamBody"
336
336
servant-server/src/Servant/Server/Internal.hs+3−3
@@ -71,7 +71,7 @@ import Servant.API
71 FramingUnrender (..), FromSourceIO (..), Header', If,
71 FramingUnrender (..), FromSourceIO (..), Header', If,
72 IsSecure (..), QueryFlag, QueryParam', QueryParams, Raw,
72 IsSecure (..), QueryFlag, QueryParam', QueryParams, Raw,
73 ReflectMethod (reflectMethod), RemoteHost, ReqBody',
73 ReflectMethod (reflectMethod), RemoteHost, ReqBody',
74− SBool (..), SBoolI (..), SourceIO, Stream, StreamBody,
74+ SBool (..), SBoolI (..), SourceIO, Stream, StreamBody',
75 Summary, ToSourceIO (..), Vault, Verb, WithNamedContext)
75 Summary, ToSourceIO (..), Vault, Verb, WithNamedContext)
76import Servant.API.ContentTypes
76import Servant.API.ContentTypes
77 (AcceptHeader (..), AllCTRender (..), AllCTUnrender (..),
77 (AcceptHeader (..), AllCTRender (..), AllCTUnrender (..),
@@ -610,9 +610,9 @@ instance ( AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods
610instance
610instance
611 ( FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk
611 ( FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk
612 , HasServer api context
612 , HasServer api context
613− ) => HasServer (StreamBody framing ctype a :> api) context
613+ ) => HasServer (StreamBody' mods framing ctype a :> api) context
614 where
614 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
616
616
617 hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s
617 hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s
618
618
servant-server/test/Servant/ServerSpec.hs+11−9
@@ -12,24 +12,26 @@
12
12
13module Servant.ServerSpec where
13module Servant.ServerSpec where
14
14
15+import Prelude ()
16+import Prelude.Compat
17+
15import Control.Monad
18import Control.Monad
16 (forM_, unless, when)
19 (forM_, unless, when)
17import Control.Monad.Error.Class
20import Control.Monad.Error.Class
18 (MonadError (..))
21 (MonadError (..))
19import Data.Aeson
22import Data.Aeson
20 (FromJSON, ToJSON, decode', encode)
23 (FromJSON, ToJSON, decode', encode)
21−import qualified Data.ByteString as BS
24+import qualified Data.ByteString as BS
22−import qualified Data.ByteString.Base64 as Base64
25+import qualified Data.ByteString.Base64 as Base64
23import Data.Char
26import Data.Char
24 (toUpper)
27 (toUpper)
25−import Data.Monoid
26import Data.Proxy
28import Data.Proxy
27 (Proxy (Proxy))
29 (Proxy (Proxy))
28import Data.String
30import Data.String
29 (fromString)
31 (fromString)
30import Data.String.Conversions
32import Data.String.Conversions
31 (cs)
33 (cs)
32−import qualified Data.Text as T
34+import qualified Data.Text as T
33import GHC.Generics
35import GHC.Generics
34 (Generic)
36 (Generic)
35import Network.HTTP.Types
37import Network.HTTP.Types
@@ -42,25 +44,25 @@ import Network.Wai
42import Network.Wai.Test
44import Network.Wai.Test
43 (defaultRequest, request, runSession, simpleBody,
45 (defaultRequest, request, runSession, simpleBody,
44 simpleHeaders, simpleStatus)
46 simpleHeaders, simpleStatus)
45−import qualified Servant.Types.SourceT as S
46import Servant.API
47import Servant.API
47 ((:<|>) (..), (:>), AuthProtect, BasicAuth,
48 ((:<|>) (..), (:>), AuthProtect, BasicAuth,
48 BasicAuthData (BasicAuthData), Capture, CaptureAll, Delete,
49 BasicAuthData (BasicAuthData), Capture, CaptureAll, Delete,
49 EmptyAPI, Get, Header, Headers, HttpVersion, IsSecure (..),
50 EmptyAPI, Get, Header, Headers, HttpVersion, IsSecure (..),
50 JSON, NoContent (..), NoFraming, OctetStream, Patch,
51 JSON, NoContent (..), NoFraming, OctetStream, Patch,
51 PlainText, Post, Put, QueryFlag, QueryParam, QueryParams, Raw,
52 PlainText, Post, Put, QueryFlag, QueryParam, QueryParams, Raw,
52− RemoteHost, ReqBody, StdMethod (..), Stream,
53+ RemoteHost, ReqBody, SourceIO, StdMethod (..), Stream, Verb,
53− SourceIO, Verb, addHeader)
54+ addHeader)
54−import Servant.Test.ComprehensiveAPI
55import Servant.Server
55import Servant.Server
56 (Context ((:.), EmptyContext), Handler, Server, Tagged (..),
56 (Context ((:.), EmptyContext), Handler, Server, Tagged (..),
57 emptyServer, err401, err403, err404, serve, serveWithContext)
57 emptyServer, err401, err403, err404, serve, serveWithContext)
58+import Servant.Test.ComprehensiveAPI
59+import qualified Servant.Types.SourceT as S
58import Test.Hspec
60import Test.Hspec
59 (Spec, context, describe, it, shouldBe, shouldContain)
61 (Spec, context, describe, it, shouldBe, shouldContain)
60import Test.Hspec.Wai
62import Test.Hspec.Wai
61 (get, liftIO, matchHeaders, matchStatus, shouldRespondWith,
63 (get, liftIO, matchHeaders, matchStatus, shouldRespondWith,
62 with, (<:>))
64 with, (<:>))
63−import qualified Test.Hspec.Wai as THW
65+import qualified Test.Hspec.Wai as THW
64
66
65import Servant.Server.Experimental.Auth
67import Servant.Server.Experimental.Auth
66 (AuthHandler, AuthServerData, mkAuthHandler)
68 (AuthHandler, AuthServerData, mkAuthHandler)
servant/src/Servant/API.hs+7−7
@@ -110,14 +110,14 @@ import Servant.API.ReqBody
110 (ReqBody, ReqBody')
110 (ReqBody, ReqBody')
111import Servant.API.ResponseHeaders
111import Servant.API.ResponseHeaders
112 (AddHeader, BuildHeadersTo (buildHeadersTo),
112 (AddHeader, BuildHeadersTo (buildHeadersTo),
113− GetHeaders (getHeaders), HList (..), Headers (..),
113+ GetHeaders (getHeaders), HList (..), HasResponseHeader,
114− ResponseHeader (..), addHeader, getHeadersHList, getResponse,
114+ Headers (..), ResponseHeader (..), addHeader, getHeadersHList,
115− noHeader, HasResponseHeader, lookupResponseHeader)
115+ getResponse, lookupResponseHeader, noHeader)
116import Servant.API.Stream
116import Servant.API.Stream
117− (FramingRender (..), FramingUnrender (..),
117+ (FramingRender (..), FramingUnrender (..), FromSourceIO (..),
118− FromSourceIO (..), NetstringFraming, NewlineFraming,
118+ NetstringFraming, NewlineFraming, NoFraming, SourceIO, Stream,
119− NoFraming, SourceIO, Stream, StreamBody, SourceIO,
120− StreamGet, StreamPost, ToSourceIO (..))
119+ StreamBody, StreamBody', StreamGet, StreamPost,
120+ ToSourceIO (..))
121import Servant.API.Sub
121import Servant.API.Sub
122 ((:>))
122 ((:>))
123import Servant.API.Vault
123import Servant.API.Vault
servant/src/Servant/API/Stream.hs+4−3
@@ -17,6 +17,7 @@ module Servant.API.Stream (
17 StreamGet,
17 StreamGet,
18 StreamPost,
18 StreamPost,
19 StreamBody,
19 StreamBody,
20+ StreamBody',
20 -- * Source
21 -- * Source
21 --
22 --
22 -- | 'SourceIO' are equivalent to some *source* in streaming libraries.
23 -- | 'SourceIO' are equivalent to some *source* in streaming libraries.
@@ -71,9 +72,9 @@ type StreamGet = Stream 'GET 200
71type StreamPost = Stream 'POST 200
72type StreamPost = Stream 'POST 200
72
73
73-- | A stream request body.
74-- | A stream request body.
74−--
75+type StreamBody = StreamBody' '[]
75−-- TODO: add mods
76+
76−data StreamBody (framing :: *) (contentType :: *) (a :: *)
77+data StreamBody' (mods :: [*]) (framing :: *) (contentType :: *) (a :: *)
77 deriving (Typeable, Generic)
78 deriving (Typeable, Generic)
78
79
79-------------------------------------------------------------------------------
80-------------------------------------------------------------------------------
servant/src/Servant/Links.hs+3−3
@@ -170,7 +170,7 @@ import Servant.API.RemoteHost
170import Servant.API.ReqBody
170import Servant.API.ReqBody
171 (ReqBody')
171 (ReqBody')
172import Servant.API.Stream
172import Servant.API.Stream
173− (Stream, StreamBody)
173+ (Stream, StreamBody')
174import Servant.API.Sub
174import Servant.API.Sub
175 (type (:>))
175 (type (:>))
176import Servant.API.TypeLevel
176import Servant.API.TypeLevel
@@ -482,8 +482,8 @@ instance HasLink sub => HasLink (ReqBody' mods ct a :> sub) where
482 type MkLink (ReqBody' mods ct a :> sub) r = MkLink sub r
482 type MkLink (ReqBody' mods ct a :> sub) r = MkLink sub r
483 toLink toA _ = toLink toA (Proxy :: Proxy sub)
483 toLink toA _ = toLink toA (Proxy :: Proxy sub)
484
484
485−instance HasLink sub => HasLink (StreamBody framing ct a :> sub) where
485+instance HasLink sub => HasLink (StreamBody' mods framing ct a :> sub) where
486− type MkLink (StreamBody framing ct a :> sub) r = MkLink sub r
486+ type MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub r
487 toLink toA _ = toLink toA (Proxy :: Proxy sub)
487 toLink toA _ = toLink toA (Proxy :: Proxy sub)
488
488
489instance (ToHttpApiData v, HasLink sub)
489instance (ToHttpApiData v, HasLink sub)
servant/src/Servant/Test/ComprehensiveAPI.hs+1−1
@@ -22,7 +22,7 @@ type RawEndpoint =
22 "raw" :> Raw
22 "raw" :> Raw
23
23
24type StreamingEndpoint =
24type 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)
26
26
27type EmptyEndpoint =
27type EmptyEndpoint =
28 "empty-api" :> EmptyAPI
28 "empty-api" :> EmptyAPI