diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-10-15 22:09:28 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-10-15 22:09:28 -0700 |
commit | a1f7a4263f56a4843b6c03ef4b986715f2bdb82d (patch) | |
tree | 07797547a551410bf44e2389eb4576d6ef62b76b /src | |
parent | 5e1c4223899cb24ecf5f4ad1fd26c3ac22841e77 (diff) | |
download | pandoc-a1f7a4263f56a4843b6c03ef4b986715f2bdb82d.tar.gz |
Class: add stRequestHeaders to CommonState, and setRequestHeader.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Class.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index 2b1943140..451d430ca 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -57,6 +57,7 @@ module Text.Pandoc.Class ( PandocMonad(..) , readFileFromDirs , report , setTrace + , setRequestHeader , getLog , setVerbosity , getVerbosity @@ -245,6 +246,15 @@ report msg = do setTrace :: PandocMonad m => Bool -> m () setTrace useTracing = modifyCommonState $ \st -> st{stTrace = useTracing} +-- | Set request header to use in HTTP requests. +setRequestHeader :: PandocMonad m + => String -- ^ Header name + -> String -- ^ Value + -> m () +setRequestHeader name val = modifyCommonState $ \st -> + st{ stRequestHeaders = + (name, val) : filter (\(n,_) -> n /= name) (stRequestHeaders st) } + -- | Initialize the media bag. setMediaBag :: PandocMonad m => MediaBag -> m () setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb} @@ -315,6 +325,8 @@ data CommonState = CommonState { stLog :: [LogMessage] -- ^ Directory to search for data files , stSourceURL :: Maybe String -- ^ Absolute URL + dir of 1st source file + , stRequestHeaders :: [(String, String)] + -- ^ Headers to add for HTTP requests , stMediaBag :: MediaBag -- ^ Media parsed from binary containers , stTranslations :: Maybe @@ -338,6 +350,7 @@ instance Default CommonState where def = CommonState { stLog = [] , stUserDataDir = Nothing , stSourceURL = Nothing + , stRequestHeaders = [] , stMediaBag = mempty , stTranslations = Nothing , stInputFiles = [] |