{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Network.HTTP2.H2.HPACK (
hpackEncodeHeader,
hpackEncodeHeaderRest,
hpackDecodeHeader,
hpackDecodeTrailer,
hpackDiscardHeader,
just,
fixHeaders,
) where
import qualified Control.Exception as E
import qualified Data.ByteString as BS
import Data.ByteString.Internal (create)
import qualified Data.ByteString.Lazy as BS.Lazy
import Foreign.Marshal.Alloc (free, mallocBytes)
import Foreign.Marshal.Utils (copyBytes)
import Network.ByteOrder
import Network.HTTP.Semantics
import Network.HTTP.Types
import Imports
import Network.HPACK
import Network.HTTP2.Frame
import Network.HTTP2.H2.Context
import Network.HTTP2.H2.Types
fixHeaders :: ResponseHeaders -> ResponseHeaders
ResponseHeaders
hdr = ResponseHeaders -> ResponseHeaders
deleteUnnecessaryHeaders ResponseHeaders
hdr
deleteUnnecessaryHeaders :: ResponseHeaders -> ResponseHeaders
ResponseHeaders
hdr = (Header -> Bool) -> ResponseHeaders -> ResponseHeaders
forall a. (a -> Bool) -> [a] -> [a]
filter Header -> Bool
forall {b}. (CI ByteString, b) -> Bool
del ResponseHeaders
hdr
where
del :: (CI ByteString, b) -> Bool
del (CI ByteString
k, b
_) = CI ByteString
k CI ByteString -> [CI ByteString] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [CI ByteString]
headersToBeRemoved
headersToBeRemoved :: [HeaderName]
=
[ CI ByteString
hConnection
, CI ByteString
"Transfer-Encoding"
]
strategy :: EncodeStrategy
strategy :: EncodeStrategy
strategy = EncodeStrategy{compressionAlgo :: CompressionAlgo
compressionAlgo = CompressionAlgo
Linear, useHuffman :: Bool
useHuffman = Bool
False}
hpackEncodeHeader
:: Context
-> Buffer
-> BufferSize
-> TokenHeaderList
-> IO (TokenHeaderList, Int)
Context{Bool
STM Bool
TVar Bool
TVar BufferSize
TVar (Maybe BufferSize)
TVar (Maybe SomeException)
TVar ByteString
TVar TxFlow
TVar EvenStreamTable
TVar OddStreamTable
IORef Bool
IORef BufferSize
IORef (Maybe HeaderContinuation)
IORef RxFlow
IORef IntSet
IORef Settings
DynamicTable
Rate
Settings
ControlQ
Manager
SockAddr
TQueue Output
Role
RoleInfo
ThreadManager
BufferSize -> TokenHeaderTable -> IO ()
role :: Role
roleInfo :: RoleInfo
mySettings :: Settings
myFirstSettings :: IORef Bool
peerSettings :: IORef Settings
oddStreamTable :: TVar OddStreamTable
evenStreamTable :: TVar EvenStreamTable
continued :: IORef (Maybe HeaderContinuation)
myStreamId :: TVar BufferSize
peerStreamId :: IORef BufferSize
peerLastStreamId :: TVar BufferSize
outputBufferLimit :: IORef BufferSize
outputQ :: TQueue Output
outputQStreamID :: TVar BufferSize
controlQ :: ControlQ
encodeDynamicTable :: DynamicTable
decodeDynamicTable :: DynamicTable
txFlow :: TVar TxFlow
rxFlow :: IORef RxFlow
pingRate :: Rate
settingsRate :: Rate
emptyFrameRate :: Rate
rstRate :: Rate
mySockAddr :: SockAddr
peerSockAddr :: SockAddr
threadManager :: ThreadManager
timeoutManager :: Manager
receiverDone :: TVar (Maybe SomeException)
stopReceiving :: TVar Bool
receiverStoppable :: Bool
appDone :: STM Bool
informationalCallback :: BufferSize -> TokenHeaderTable -> IO ()
peerGoAway :: TVar (Maybe BufferSize)
myGoAway :: TVar (Maybe BufferSize)
pingAcked :: TVar ByteString
activeRequests :: TVar BufferSize
resetByMe :: IORef IntSet
activeRequests :: Context -> TVar BufferSize
appDone :: Context -> STM Bool
continued :: Context -> IORef (Maybe HeaderContinuation)
controlQ :: Context -> ControlQ
decodeDynamicTable :: Context -> DynamicTable
emptyFrameRate :: Context -> Rate
encodeDynamicTable :: Context -> DynamicTable
evenStreamTable :: Context -> TVar EvenStreamTable
informationalCallback :: Context -> BufferSize -> TokenHeaderTable -> IO ()
myFirstSettings :: Context -> IORef Bool
myGoAway :: Context -> TVar (Maybe BufferSize)
mySettings :: Context -> Settings
mySockAddr :: Context -> SockAddr
myStreamId :: Context -> TVar BufferSize
oddStreamTable :: Context -> TVar OddStreamTable
outputBufferLimit :: Context -> IORef BufferSize
outputQ :: Context -> TQueue Output
outputQStreamID :: Context -> TVar BufferSize
peerGoAway :: Context -> TVar (Maybe BufferSize)
peerLastStreamId :: Context -> TVar BufferSize
peerSettings :: Context -> IORef Settings
peerSockAddr :: Context -> SockAddr
peerStreamId :: Context -> IORef BufferSize
pingAcked :: Context -> TVar ByteString
pingRate :: Context -> Rate
receiverDone :: Context -> TVar (Maybe SomeException)
receiverStoppable :: Context -> Bool
resetByMe :: Context -> IORef IntSet
role :: Context -> Role
roleInfo :: Context -> RoleInfo
rstRate :: Context -> Rate
rxFlow :: Context -> IORef RxFlow
settingsRate :: Context -> Rate
stopReceiving :: Context -> TVar Bool
threadManager :: Context -> ThreadManager
timeoutManager :: Context -> Manager
txFlow :: Context -> TVar TxFlow
..} Buffer
buf BufferSize
siz TokenHeaderList
ths =
Buffer
-> BufferSize
-> EncodeStrategy
-> Bool
-> DynamicTable
-> TokenHeaderList
-> IO (TokenHeaderList, BufferSize)
encodeTokenHeader Buffer
buf BufferSize
siz EncodeStrategy
strategy Bool
True DynamicTable
encodeDynamicTable TokenHeaderList
ths
hpackEncodeHeaderLoop
:: Context
-> Buffer
-> BufferSize
-> TokenHeaderList
-> IO (TokenHeaderList, Int)
Context{Bool
STM Bool
TVar Bool
TVar BufferSize
TVar (Maybe BufferSize)
TVar (Maybe SomeException)
TVar ByteString
TVar TxFlow
TVar EvenStreamTable
TVar OddStreamTable
IORef Bool
IORef BufferSize
IORef (Maybe HeaderContinuation)
IORef RxFlow
IORef IntSet
IORef Settings
DynamicTable
Rate
Settings
ControlQ
Manager
SockAddr
TQueue Output
Role
RoleInfo
ThreadManager
BufferSize -> TokenHeaderTable -> IO ()
activeRequests :: Context -> TVar BufferSize
appDone :: Context -> STM Bool
continued :: Context -> IORef (Maybe HeaderContinuation)
controlQ :: Context -> ControlQ
decodeDynamicTable :: Context -> DynamicTable
emptyFrameRate :: Context -> Rate
encodeDynamicTable :: Context -> DynamicTable
evenStreamTable :: Context -> TVar EvenStreamTable
informationalCallback :: Context -> BufferSize -> TokenHeaderTable -> IO ()
myFirstSettings :: Context -> IORef Bool
myGoAway :: Context -> TVar (Maybe BufferSize)
mySettings :: Context -> Settings
mySockAddr :: Context -> SockAddr
myStreamId :: Context -> TVar BufferSize
oddStreamTable :: Context -> TVar OddStreamTable
outputBufferLimit :: Context -> IORef BufferSize
outputQ :: Context -> TQueue Output
outputQStreamID :: Context -> TVar BufferSize
peerGoAway :: Context -> TVar (Maybe BufferSize)
peerLastStreamId :: Context -> TVar BufferSize
peerSettings :: Context -> IORef Settings
peerSockAddr :: Context -> SockAddr
peerStreamId :: Context -> IORef BufferSize
pingAcked :: Context -> TVar ByteString
pingRate :: Context -> Rate
receiverDone :: Context -> TVar (Maybe SomeException)
receiverStoppable :: Context -> Bool
resetByMe :: Context -> IORef IntSet
role :: Context -> Role
roleInfo :: Context -> RoleInfo
rstRate :: Context -> Rate
rxFlow :: Context -> IORef RxFlow
settingsRate :: Context -> Rate
stopReceiving :: Context -> TVar Bool
threadManager :: Context -> ThreadManager
timeoutManager :: Context -> Manager
txFlow :: Context -> TVar TxFlow
role :: Role
roleInfo :: RoleInfo
mySettings :: Settings
myFirstSettings :: IORef Bool
peerSettings :: IORef Settings
oddStreamTable :: TVar OddStreamTable
evenStreamTable :: TVar EvenStreamTable
continued :: IORef (Maybe HeaderContinuation)
myStreamId :: TVar BufferSize
peerStreamId :: IORef BufferSize
peerLastStreamId :: TVar BufferSize
outputBufferLimit :: IORef BufferSize
outputQ :: TQueue Output
outputQStreamID :: TVar BufferSize
controlQ :: ControlQ
encodeDynamicTable :: DynamicTable
decodeDynamicTable :: DynamicTable
txFlow :: TVar TxFlow
rxFlow :: IORef RxFlow
pingRate :: Rate
settingsRate :: Rate
emptyFrameRate :: Rate
rstRate :: Rate
mySockAddr :: SockAddr
peerSockAddr :: SockAddr
threadManager :: ThreadManager
timeoutManager :: Manager
receiverDone :: TVar (Maybe SomeException)
stopReceiving :: TVar Bool
receiverStoppable :: Bool
appDone :: STM Bool
informationalCallback :: BufferSize -> TokenHeaderTable -> IO ()
peerGoAway :: TVar (Maybe BufferSize)
myGoAway :: TVar (Maybe BufferSize)
pingAcked :: TVar ByteString
activeRequests :: TVar BufferSize
resetByMe :: IORef IntSet
..} Buffer
buf BufferSize
siz TokenHeaderList
hs =
Buffer
-> BufferSize
-> EncodeStrategy
-> Bool
-> DynamicTable
-> TokenHeaderList
-> IO (TokenHeaderList, BufferSize)
encodeTokenHeader Buffer
buf BufferSize
siz EncodeStrategy
strategy Bool
False DynamicTable
encodeDynamicTable TokenHeaderList
hs
hpackEncodeHeaderRest
:: Context
-> BufferSize
-> TokenHeaderList
-> IO BS.Lazy.ByteString
Context
ctx = [ByteString] -> BufferSize -> TokenHeaderList -> IO ByteString
go []
where
go :: [ByteString] -> BufferSize -> TokenHeaderList -> IO ByteString
go [ByteString]
acc BufferSize
_ [] = ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ByteString
BS.Lazy.fromChunks ([ByteString] -> [ByteString]
forall a. [a] -> [a]
reverse [ByteString]
acc)
go [ByteString]
acc BufferSize
siz TokenHeaderList
ths = do
(chunk, ths') <- IO Buffer
-> (Buffer -> IO ())
-> (Buffer -> IO (ByteString, TokenHeaderList))
-> IO (ByteString, TokenHeaderList)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracket (BufferSize -> IO Buffer
forall a. BufferSize -> IO (Ptr a)
mallocBytes BufferSize
siz) Buffer -> IO ()
forall a. Ptr a -> IO ()
free ((Buffer -> IO (ByteString, TokenHeaderList))
-> IO (ByteString, TokenHeaderList))
-> (Buffer -> IO (ByteString, TokenHeaderList))
-> IO (ByteString, TokenHeaderList)
forall a b. (a -> b) -> a -> b
$ \Buffer
buf -> do
(ths', len) <- Context
-> Buffer
-> BufferSize
-> TokenHeaderList
-> IO (TokenHeaderList, BufferSize)
hpackEncodeHeaderLoop Context
ctx Buffer
buf BufferSize
siz TokenHeaderList
ths
chunk <- create len $ \Buffer
p -> Buffer -> Buffer -> BufferSize -> IO ()
forall a. Ptr a -> Ptr a -> BufferSize -> IO ()
copyBytes Buffer
p Buffer
buf BufferSize
len
return (chunk, ths')
if BS.null chunk
then go acc (siz * 2) ths
else go (chunk : acc) siz ths'
hpackDecodeHeader
:: HeaderBlockFragment -> StreamId -> Context -> IO TokenHeaderTable
ByteString
hdrblk BufferSize
sid Context
ctx = do
tbl@(_, vt) <- ShortByteString
-> ByteString -> BufferSize -> Context -> IO TokenHeaderTable
hpackDecode ShortByteString
"illegal header" ByteString
hdrblk BufferSize
sid Context
ctx
if isClient ctx || checkRequestHeader vt
then return tbl
else E.throwIO $ StreamErrorIsSent ProtocolError sid "illegal header"
hpackDecodeTrailer
:: HeaderBlockFragment -> StreamId -> Context -> IO TokenHeaderTable
hpackDecodeTrailer :: ByteString -> BufferSize -> Context -> IO TokenHeaderTable
hpackDecodeTrailer = ShortByteString
-> ByteString -> BufferSize -> Context -> IO TokenHeaderTable
hpackDecode ShortByteString
"illegal trailer"
hpackDiscardHeader :: HeaderBlockFragment -> StreamId -> Context -> IO ()
ByteString
hdrblk BufferSize
sid Context
ctx =
IO TokenHeaderTable -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ShortByteString
-> ByteString -> BufferSize -> Context -> IO TokenHeaderTable
hpackDecode ShortByteString
"illegal header" ByteString
hdrblk BufferSize
sid Context
ctx) IO () -> (HTTP2Error -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch` HTTP2Error -> IO ()
ignore
where
ignore :: HTTP2Error -> IO ()
ignore StreamErrorIsSent{} = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
ignore HTTP2Error
e = HTTP2Error -> IO ()
forall e a. (HasCallStack, Exception e) => e -> IO a
E.throwIO HTTP2Error
e
hpackDecode
:: ReasonPhrase
-> HeaderBlockFragment
-> StreamId
-> Context
-> IO TokenHeaderTable
hpackDecode :: ShortByteString
-> ByteString -> BufferSize -> Context -> IO TokenHeaderTable
hpackDecode ShortByteString
illegal ByteString
hdrblk BufferSize
sid Context{Bool
STM Bool
TVar Bool
TVar BufferSize
TVar (Maybe BufferSize)
TVar (Maybe SomeException)
TVar ByteString
TVar TxFlow
TVar EvenStreamTable
TVar OddStreamTable
IORef Bool
IORef BufferSize
IORef (Maybe HeaderContinuation)
IORef RxFlow
IORef IntSet
IORef Settings
DynamicTable
Rate
Settings
ControlQ
Manager
SockAddr
TQueue Output
Role
RoleInfo
ThreadManager
BufferSize -> TokenHeaderTable -> IO ()
activeRequests :: Context -> TVar BufferSize
appDone :: Context -> STM Bool
continued :: Context -> IORef (Maybe HeaderContinuation)
controlQ :: Context -> ControlQ
decodeDynamicTable :: Context -> DynamicTable
emptyFrameRate :: Context -> Rate
encodeDynamicTable :: Context -> DynamicTable
evenStreamTable :: Context -> TVar EvenStreamTable
informationalCallback :: Context -> BufferSize -> TokenHeaderTable -> IO ()
myFirstSettings :: Context -> IORef Bool
myGoAway :: Context -> TVar (Maybe BufferSize)
mySettings :: Context -> Settings
mySockAddr :: Context -> SockAddr
myStreamId :: Context -> TVar BufferSize
oddStreamTable :: Context -> TVar OddStreamTable
outputBufferLimit :: Context -> IORef BufferSize
outputQ :: Context -> TQueue Output
outputQStreamID :: Context -> TVar BufferSize
peerGoAway :: Context -> TVar (Maybe BufferSize)
peerLastStreamId :: Context -> TVar BufferSize
peerSettings :: Context -> IORef Settings
peerSockAddr :: Context -> SockAddr
peerStreamId :: Context -> IORef BufferSize
pingAcked :: Context -> TVar ByteString
pingRate :: Context -> Rate
receiverDone :: Context -> TVar (Maybe SomeException)
receiverStoppable :: Context -> Bool
resetByMe :: Context -> IORef IntSet
role :: Context -> Role
roleInfo :: Context -> RoleInfo
rstRate :: Context -> Rate
rxFlow :: Context -> IORef RxFlow
settingsRate :: Context -> Rate
stopReceiving :: Context -> TVar Bool
threadManager :: Context -> ThreadManager
timeoutManager :: Context -> Manager
txFlow :: Context -> TVar TxFlow
role :: Role
roleInfo :: RoleInfo
mySettings :: Settings
myFirstSettings :: IORef Bool
peerSettings :: IORef Settings
oddStreamTable :: TVar OddStreamTable
evenStreamTable :: TVar EvenStreamTable
continued :: IORef (Maybe HeaderContinuation)
myStreamId :: TVar BufferSize
peerStreamId :: IORef BufferSize
peerLastStreamId :: TVar BufferSize
outputBufferLimit :: IORef BufferSize
outputQ :: TQueue Output
outputQStreamID :: TVar BufferSize
controlQ :: ControlQ
encodeDynamicTable :: DynamicTable
decodeDynamicTable :: DynamicTable
txFlow :: TVar TxFlow
rxFlow :: IORef RxFlow
pingRate :: Rate
settingsRate :: Rate
emptyFrameRate :: Rate
rstRate :: Rate
mySockAddr :: SockAddr
peerSockAddr :: SockAddr
threadManager :: ThreadManager
timeoutManager :: Manager
receiverDone :: TVar (Maybe SomeException)
stopReceiving :: TVar Bool
receiverStoppable :: Bool
appDone :: STM Bool
informationalCallback :: BufferSize -> TokenHeaderTable -> IO ()
peerGoAway :: TVar (Maybe BufferSize)
myGoAway :: TVar (Maybe BufferSize)
pingAcked :: TVar ByteString
activeRequests :: TVar BufferSize
resetByMe :: IORef IntSet
..} =
DynamicTable -> ByteString -> IO TokenHeaderTable
decodeTokenHeader DynamicTable
decodeDynamicTable ByteString
hdrblk IO TokenHeaderTable
-> (DecodeError -> IO TokenHeaderTable) -> IO TokenHeaderTable
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch` DecodeError -> IO TokenHeaderTable
forall {a}. DecodeError -> IO a
handl
where
handl :: DecodeError -> IO a
handl DecodeError
IllegalHeaderName =
HTTP2Error -> IO a
forall e a. (HasCallStack, Exception e) => e -> IO a
E.throwIO (HTTP2Error -> IO a) -> HTTP2Error -> IO a
forall a b. (a -> b) -> a -> b
$ ErrorCode -> BufferSize -> ShortByteString -> HTTP2Error
StreamErrorIsSent ErrorCode
ProtocolError BufferSize
sid ShortByteString
illegal
handl DecodeError
TooLargeHeader =
HTTP2Error -> IO a
forall e a. (HasCallStack, Exception e) => e -> IO a
E.throwIO (HTTP2Error -> IO a) -> HTTP2Error -> IO a
forall a b. (a -> b) -> a -> b
$ ErrorCode -> BufferSize -> ShortByteString -> HTTP2Error
StreamErrorIsSent ErrorCode
ProtocolError BufferSize
sid ShortByteString
"header list too large"
handl DecodeError
e = do
let msg :: ShortByteString
msg = String -> ShortByteString
forall a. IsString a => String -> a
fromString (String -> ShortByteString) -> String -> ShortByteString
forall a b. (a -> b) -> a -> b
$ DecodeError -> String
forall a. Show a => a -> String
show DecodeError
e
HTTP2Error -> IO a
forall e a. (HasCallStack, Exception e) => e -> IO a
E.throwIO (HTTP2Error -> IO a) -> HTTP2Error -> IO a
forall a b. (a -> b) -> a -> b
$ ErrorCode -> BufferSize -> ShortByteString -> HTTP2Error
ConnectionErrorIsSent ErrorCode
CompressionError BufferSize
sid ShortByteString
msg
{-# INLINE checkRequestHeader #-}
checkRequestHeader :: ValueTable -> Bool
ValueTable
reqvt
| Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isJust Maybe ByteString
mStatus = Bool
False
| Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing Maybe ByteString
mMethod = Bool
False
| Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isJust Maybe ByteString
mConnection = Bool
False
| Maybe ByteString -> (ByteString -> Bool) -> Bool
forall a. Maybe a -> (a -> Bool) -> Bool
just Maybe ByteString
mTE (ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
/= ByteString
"trailers") = Bool
False
| Maybe ByteString
mMethod Maybe ByteString -> Maybe ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"CONNECT" =
Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing Maybe ByteString
mPath
Bool -> Bool -> Bool
&& Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing Maybe ByteString
mScheme
Bool -> Bool -> Bool
&& Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isJust Maybe ByteString
mAuthority
Bool -> Bool -> Bool
&& Maybe ByteString -> Maybe ByteString -> Bool
checkAuth Maybe ByteString
mAuthority Maybe ByteString
mHost
| Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing Maybe ByteString
mScheme = Bool
False
| Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing Maybe ByteString
mPath = Bool
False
| Maybe ByteString
mPath Maybe ByteString -> Maybe ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"" = Bool
False
| Bool
otherwise = Maybe ByteString -> Maybe ByteString -> Bool
checkAuth Maybe ByteString
mAuthority Maybe ByteString
mHost
where
mStatus :: Maybe ByteString
mStatus = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenStatus ValueTable
reqvt
mScheme :: Maybe ByteString
mScheme = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenScheme ValueTable
reqvt
mPath :: Maybe ByteString
mPath = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenPath ValueTable
reqvt
mMethod :: Maybe ByteString
mMethod = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenMethod ValueTable
reqvt
mConnection :: Maybe ByteString
mConnection = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenConnection ValueTable
reqvt
mTE :: Maybe ByteString
mTE = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenTE ValueTable
reqvt
mAuthority :: Maybe ByteString
mAuthority = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenAuthority ValueTable
reqvt
mHost :: Maybe ByteString
mHost = Token -> ValueTable -> Maybe ByteString
getFieldValue Token
tokenHost ValueTable
reqvt
checkAuth :: Maybe ByteString -> Maybe ByteString -> Bool
checkAuth :: Maybe ByteString -> Maybe ByteString -> Bool
checkAuth Maybe ByteString
Nothing Maybe ByteString
Nothing = Bool
False
checkAuth (Just ByteString
a) (Just ByteString
h) | ByteString
a ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
/= ByteString
h = Bool
False
checkAuth Maybe ByteString
_ Maybe ByteString
_ = Bool
True
{-# INLINE just #-}
just :: Maybe a -> (a -> Bool) -> Bool
just :: forall a. Maybe a -> (a -> Bool) -> Bool
just Maybe a
Nothing a -> Bool
_ = Bool
False
just (Just a
x) a -> Bool
p
| a -> Bool
p a
x = Bool
True
| Bool
otherwise = Bool
False