@@ -75,9 +75,9 @@ import qualified System.IO as IO (Newline (..))
7575import Text.Pandoc
7676import Text.Pandoc.Builder (setMeta)
7777import Text.Pandoc.Class (PandocIO, extractMedia, fillMediaBag, getLog,
78− setResourcePath, setTrace, report,
78+ setResourcePath, setTrace, report, setRequestHeader,
7979 setUserDataDir, readFileStrict, readDataFile,
80− readDefaultDataFile, setTranslations,
80+ readDefaultDataFile, setTranslations, openURL,
8181 setInputFiles, setOutputFile)
8282import Text.Pandoc.Highlighting (highlightingStyles)
8383import Text.Pandoc.BCP47 (parseBCP47, Lang(..))
@@ -86,7 +86,7 @@ import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
8686import Text.Pandoc.PDF (makePDF)
8787import Text.Pandoc.Process (pipeProcess)
8888import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
89−import Text.Pandoc.Shared (headerShift, isURI, openURL, ordNub,
89+import Text.Pandoc.Shared (headerShift, isURI, ordNub,
9090 safeRead, tabFilter, eastAsianLineBreakFilter)
9191import qualified Text.Pandoc.UTF8 as UTF8
9292import Text.Pandoc.XML (toEntities)
@@ -491,7 +491,10 @@ convertWithOpts opts = do
491491 when (readerName == "markdown_github" ||
492492 writerName == "markdown_github") $
493493 report $ Deprecated "markdown_github" "Use gfm instead."
494+
494495 setResourcePath (optResourcePath opts)
496+ mapM_ (\(n,v) -> setRequestHeader n v) (optRequestHeaders opts)
497+
495498 doc <- sourceToDoc sources >>=
496499 ( (if isJust (optExtractMedia opts)
497500 then fillMediaBag
@@ -641,6 +644,7 @@ data Opt = Opt
641644 , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
642645 , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
643646 , optResourcePath :: [FilePath] -- ^ Path to search for images etc
647+ , optRequestHeaders :: [(String, String)] -- ^ Headers for HTTP requests
644648 , optEol :: LineEnding -- ^ Style of line-endings to use
645649 , optStripComments :: Bool -- ^ Skip HTML comments
646650 } deriving (Generic, Show)
@@ -716,6 +720,7 @@ defaultOpts = Opt
716720 , optIncludeAfterBody = []
717721 , optIncludeInHeader = []
718722 , optResourcePath = ["."]
723+ , optRequestHeaders = []
719724 , optEol = Native
720725 , optStripComments = False
721726 }
@@ -863,11 +868,7 @@ readSource src = case parseURI src of
863868 BS.readFile src
864869
865870readURI :: FilePath -> PandocIO Text
866−readURI src = do
867− res <- liftIO $ openURL src
868− case res of
869− Left e -> throwError $ PandocHttpError src e
870− Right (contents, _) -> return $ UTF8.toText contents
871+readURI src = UTF8.toText . fst <$> openURL src
871872
872873readFile' :: MonadIO m => FilePath -> m B.ByteString
873874readFile' "-" = liftIO B.getContents
@@ -1161,6 +1162,14 @@ options =
11611162 "SEARCHPATH")
11621163 "" -- "Paths to search for images and other resources"
11631164
1165+ , Option "" ["request-header"]
1166+ (ReqArg
1167+ (\arg opt -> do
1168+ let (key, val) = splitField arg
1169+ return opt{ optRequestHeaders =
1170+ (key, val) : optRequestHeaders opt })
1171+ "NAME:VALUE")
1172+ ""
11641173
11651174 , Option "" ["self-contained"]
11661175 (NoArg