{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
module Network.HTTP2.Client (
run,
Scheme,
Authority,
ClientConfig,
defaultClientConfig,
scheme,
authority,
cacheLimit,
connectionWindowSize,
settings,
Settings,
defaultSettings,
headerTableSize,
enablePush,
maxConcurrentStreams,
initialWindowSize,
maxFrameSize,
maxHeaderListSize,
Config (..),
allocSimpleConfig,
freeSimpleConfig,
Client,
Request,
requestNoBody,
requestFile,
requestStreaming,
requestStreamingUnmask,
requestBuilder,
TrailersMaker,
NextTrailersMaker (..),
defaultTrailersMaker,
setRequestTrailersMaker,
Response,
responseStatus,
responseHeaders,
responseBodySize,
getResponseBodyChunk,
getResponseTrailers,
Aux,
auxPossibleClientStreams,
Method,
Path,
FileSpec (..),
FileOffset,
ByteCount,
HTTP2Error (..),
ReasonPhrase,
ErrorCode (
ErrorCode,
NoError,
ProtocolError,
InternalError,
FlowControlError,
SettingsTimeout,
StreamClosed,
FrameSizeError,
RefusedStream,
Cancel,
CompressionError,
ConnectError,
EnhanceYourCalm,
InadequateSecurity,
HTTP11Required
),
defaultReadN,
PositionReadMaker,
PositionRead,
Sentinel (..),
defaultPositionReadMaker,
) where
import Data.ByteString (ByteString)
import Data.ByteString.Builder (Builder)
import Data.IORef (readIORef)
import Network.HTTP.Types
import Network.HPACK
import Network.HTTP2.Client.Run
import Network.HTTP2.Client.Types
import Network.HTTP2.Frame
import Network.HTTP2.H2 hiding (authority, scheme)
requestNoBody :: Method -> Path -> RequestHeaders -> Request
requestNoBody :: ByteString -> ByteString -> RequestHeaders -> Request
requestNoBody ByteString
m ByteString
p RequestHeaders
hdr = OutObj -> Request
Request forall a b. (a -> b) -> a -> b
$ RequestHeaders -> OutBody -> TrailersMaker -> OutObj
OutObj RequestHeaders
hdr' OutBody
OutBodyNone TrailersMaker
defaultTrailersMaker
where
hdr' :: RequestHeaders
hdr' = ByteString -> ByteString -> RequestHeaders -> RequestHeaders
addHeaders ByteString
m ByteString
p RequestHeaders
hdr
requestFile :: Method -> Path -> RequestHeaders -> FileSpec -> Request
requestFile :: ByteString -> ByteString -> RequestHeaders -> FileSpec -> Request
requestFile ByteString
m ByteString
p RequestHeaders
hdr FileSpec
fileSpec = OutObj -> Request
Request forall a b. (a -> b) -> a -> b
$ RequestHeaders -> OutBody -> TrailersMaker -> OutObj
OutObj RequestHeaders
hdr' (FileSpec -> OutBody
OutBodyFile FileSpec
fileSpec) TrailersMaker
defaultTrailersMaker
where
hdr' :: RequestHeaders
hdr' = ByteString -> ByteString -> RequestHeaders -> RequestHeaders
addHeaders ByteString
m ByteString
p RequestHeaders
hdr
requestBuilder :: Method -> Path -> RequestHeaders -> Builder -> Request
requestBuilder :: ByteString -> ByteString -> RequestHeaders -> Builder -> Request
requestBuilder ByteString
m ByteString
p RequestHeaders
hdr Builder
builder = OutObj -> Request
Request forall a b. (a -> b) -> a -> b
$ RequestHeaders -> OutBody -> TrailersMaker -> OutObj
OutObj RequestHeaders
hdr' (Builder -> OutBody
OutBodyBuilder Builder
builder) TrailersMaker
defaultTrailersMaker
where
hdr' :: RequestHeaders
hdr' = ByteString -> ByteString -> RequestHeaders -> RequestHeaders
addHeaders ByteString
m ByteString
p RequestHeaders
hdr
requestStreaming
:: Method
-> Path
-> RequestHeaders
-> ((Builder -> IO ()) -> IO () -> IO ())
-> Request
requestStreaming :: ByteString
-> ByteString
-> RequestHeaders
-> ((Builder -> IO ()) -> IO () -> IO ())
-> Request
requestStreaming ByteString
m ByteString
p RequestHeaders
hdr (Builder -> IO ()) -> IO () -> IO ()
strmbdy = OutObj -> Request
Request forall a b. (a -> b) -> a -> b
$ RequestHeaders -> OutBody -> TrailersMaker -> OutObj
OutObj RequestHeaders
hdr' (((Builder -> IO ()) -> IO () -> IO ()) -> OutBody
OutBodyStreaming (Builder -> IO ()) -> IO () -> IO ()
strmbdy) TrailersMaker
defaultTrailersMaker
where
hdr' :: RequestHeaders
hdr' = ByteString -> ByteString -> RequestHeaders -> RequestHeaders
addHeaders ByteString
m ByteString
p RequestHeaders
hdr
requestStreamingUnmask
:: Method
-> Path
-> RequestHeaders
-> ((forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ())
-> Request
requestStreamingUnmask :: ByteString
-> ByteString
-> RequestHeaders
-> ((forall x. IO x -> IO x)
-> (Builder -> IO ()) -> IO () -> IO ())
-> Request
requestStreamingUnmask ByteString
m ByteString
p RequestHeaders
hdr (forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ()
strmbdy = OutObj -> Request
Request forall a b. (a -> b) -> a -> b
$ RequestHeaders -> OutBody -> TrailersMaker -> OutObj
OutObj RequestHeaders
hdr' (((forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ())
-> OutBody
OutBodyStreamingUnmask (forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ()
strmbdy) TrailersMaker
defaultTrailersMaker
where
hdr' :: RequestHeaders
hdr' = ByteString -> ByteString -> RequestHeaders -> RequestHeaders
addHeaders ByteString
m ByteString
p RequestHeaders
hdr
addHeaders :: Method -> Path -> RequestHeaders -> RequestHeaders
ByteString
m ByteString
p RequestHeaders
hdr = (HeaderName
":method", ByteString
m) forall a. a -> [a] -> [a]
: (HeaderName
":path", ByteString
p) forall a. a -> [a] -> [a]
: RequestHeaders
hdr
setRequestTrailersMaker :: Request -> TrailersMaker -> Request
setRequestTrailersMaker :: Request -> TrailersMaker -> Request
setRequestTrailersMaker (Request OutObj
req) TrailersMaker
tm = OutObj -> Request
Request OutObj
req{outObjTrailers :: TrailersMaker
outObjTrailers = TrailersMaker
tm}
responseStatus :: Response -> Maybe Status
responseStatus :: Response -> Maybe Status
responseStatus (Response InpObj
rsp) = HeaderTable -> Maybe Status
getStatus forall a b. (a -> b) -> a -> b
$ InpObj -> HeaderTable
inpObjHeaders InpObj
rsp
responseHeaders :: Response -> HeaderTable
(Response InpObj
rsp) = InpObj -> HeaderTable
inpObjHeaders InpObj
rsp
responseBodySize :: Response -> Maybe Int
responseBodySize :: Response -> Maybe Int
responseBodySize (Response InpObj
rsp) = InpObj -> Maybe Int
inpObjBodySize InpObj
rsp
getResponseBodyChunk :: Response -> IO ByteString
getResponseBodyChunk :: Response -> IO ByteString
getResponseBodyChunk (Response InpObj
rsp) = InpObj -> IO ByteString
inpObjBody InpObj
rsp
getResponseTrailers :: Response -> IO (Maybe HeaderTable)
getResponseTrailers :: Response -> IO (Maybe HeaderTable)
getResponseTrailers (Response InpObj
rsp) = forall a. IORef a -> IO a
readIORef (InpObj -> IORef (Maybe HeaderTable)
inpObjTrailers InpObj
rsp)