Different with-http CPP check; fix remote imports in GHCJS (#1330)

Completes the changes in #1311
This commit is contained in:
Patrick Mylund Nielsen 2019-09-20 10:44:15 -04:00 committed by GitHub
parent 0ef00bf5e3
commit fa84b0dc19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 20 deletions

View File

@ -429,6 +429,9 @@ Library
Build-Depends: semigroups == 0.18.*
Build-Depends: transformers == 0.4.2.*
Build-Depends: fail == 4.9.*
if flag(with-http)
CPP-Options:
-DWITH_HTTP
if impl(ghcjs)
Hs-Source-Dirs: ghcjs-src
Build-Depends:

View File

@ -25,7 +25,8 @@ main = do
writeFile "file1" "./file2"
Test.DocTest.doctest
[ "--fast"
[ "-DWITH_HTTP"
, "--fast"
, "-i" <> (prefix </> "src")
, "-i" <> (prefix </> "ghc-src")
, prefix </> "src/Dhall.hs"

View File

@ -258,12 +258,10 @@ corsCompliant _ _ _ = return ()
type HTTPHeader = Network.HTTP.Types.Header
fetchFromHttpUrl
:: Manager
-> URL
-> Maybe [HTTPHeader]
-> StateT Status IO Text.Text
fetchFromHttpUrl manager childURL mheaders = do
fetchFromHttpUrl :: URL -> Maybe [HTTPHeader] -> StateT Status IO Text.Text
fetchFromHttpUrl childURL mheaders = do
manager <- liftIO $ newManager
let childURLString = Text.unpack (renderURL childURL)
request <- liftIO (HTTP.parseUrlThrow childURLString)

View File

@ -17,11 +17,10 @@ import Dhall.URL (renderURL)
import Dhall.Import.Types
fetchFromHttpUrl
:: a
-> URL
:: URL
-> Maybe [(CI ByteString, ByteString)]
-> StateT Status IO Text.Text
fetchFromHttpUrl _ childURL Nothing = do
fetchFromHttpUrl childURL Nothing = do
let childURLText = renderURL childURL
let childURLString = Text.unpack childURLText
@ -35,5 +34,5 @@ fetchFromHttpUrl _ childURL Nothing = do
_ -> fail (childURLString <> " returned a non-200 status code: " <> show statusCode)
return body
fetchFromHttpUrl _ _ _ = do
fetchFromHttpUrl _ _ = do
fail "Dhall does not yet support custom headers when built using GHCJS"

View File

@ -171,8 +171,7 @@ import Dhall.Core
, bindingExprs
, chunkExprs
)
#ifdef MIN_VERSION_http_client
import Network.HTTP.Client (Manager)
#ifdef WITH_HTTP
import Dhall.Import.HTTP hiding (HTTPHeader)
#endif
import Dhall.Import.Types
@ -703,7 +702,7 @@ fetchFresh Missing = throwM (MissingImports [])
fetchRemote :: URL -> StateT Status IO Data.Text.Text
#ifndef MIN_VERSION_http_client
#ifndef WITH_HTTP
fetchRemote (url@URL { headers = maybeHeadersExpression }) = do
let maybeHeaders = fmap toHeaders maybeHeadersExpression
let urlString = Text.unpack (Dhall.Core.pretty url)
@ -711,14 +710,13 @@ fetchRemote (url@URL { headers = maybeHeadersExpression }) = do
throwMissingImport (Imported _stack (CannotImportHTTPURL urlString maybeHeaders))
#else
fetchRemote url = do
manager <- liftIO $ newManager
zoom remote (State.put (fetchFromHTTP manager))
fetchFromHTTP manager url
zoom remote (State.put fetchFromHTTP)
fetchFromHTTP url
where
fetchFromHTTP :: Manager -> URL -> StateT Status IO Data.Text.Text
fetchFromHTTP manager (url'@URL { headers = maybeHeadersExpression }) = do
fetchFromHTTP :: URL -> StateT Status IO Data.Text.Text
fetchFromHTTP (url'@URL { headers = maybeHeadersExpression }) = do
let maybeHeaders = fmap toHeaders maybeHeadersExpression
fetchFromHttpUrl manager url' maybeHeaders
fetchFromHttpUrl url' maybeHeaders
#endif
-- | Given a well-typed (of type `List { header : Text, value Text }` or