summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/SlackBuilder/Download.hs15
-rw-r--r--lib/SlackBuilder/Trans.hs4
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/SlackBuilder/Download.hs b/lib/SlackBuilder/Download.hs
index cf8b496..37f0eed 100644
--- a/lib/SlackBuilder/Download.hs
+++ b/lib/SlackBuilder/Download.hs
@@ -51,6 +51,7 @@ import Text.URI (URI(..))
import qualified Text.URI as URI
import Network.HTTP.Req
( useHttpsURI
+ , useURI
, HEAD(..)
, NoReqBody(..)
, req
@@ -258,7 +259,7 @@ download uri packagePath = runReq defaultHttpConfig go
$ URI.unRText
$ NonEmpty.last
$ snd uriPath
- | otherwise = throwM $ HttpsUrlExpected uri
+ | otherwise = throwM $ UnsupportedUrlType uri
readResponse :: FilePath -> Response BodyReader -> IO (FilePath, Digest MD5)
readResponse downloadFileName response = do
let attachmentName = dispositionAttachment response
@@ -347,7 +348,11 @@ reqGet :: (MonadThrow m, MonadHttp m)
=> URI
-> (Response BodyReader -> IO a)
-> m a
-reqGet uri bodyReader
- | Just (httpsURI, httpsOptions) <- useHttpsURI uri =
- reqBr GET httpsURI NoReqBody httpsOptions bodyReader
- | otherwise = throwM $ HttpsUrlExpected uri
+reqGet uri bodyReader =
+ case useURI uri of
+ Just urlWithOptions
+ | Left (httpsURI, httpsOptions) <- urlWithOptions ->
+ reqBr GET httpsURI NoReqBody httpsOptions bodyReader
+ | Right (httpsURI, httpsOptions) <- urlWithOptions ->
+ reqBr GET httpsURI NoReqBody httpsOptions bodyReader
+ _ -> throwM $ UnsupportedUrlType uri
diff --git a/lib/SlackBuilder/Trans.hs b/lib/SlackBuilder/Trans.hs
index 515c1d4..dea0d4b 100644
--- a/lib/SlackBuilder/Trans.hs
+++ b/lib/SlackBuilder/Trans.hs
@@ -23,7 +23,7 @@ import qualified Codec.Compression.Lzma as Lzma
data SlackBuilderException
= UpdaterNotFound Text
- | HttpsUrlExpected URI
+ | UnsupportedUrlType URI
| LzmaDecompressionFailed Lzma.LzmaRet
deriving Show
@@ -31,7 +31,7 @@ instance Exception SlackBuilderException
where
displayException (UpdaterNotFound updateName) = Text.unpack
$ Text.concat ["Requested package \"", updateName, "\" was not found"]
- displayException (HttpsUrlExpected givenURI) = Text.unpack
+ displayException (UnsupportedUrlType givenURI) = Text.unpack
$ "Only https URLs are supported, got: " <> URI.render givenURI
displayException (LzmaDecompressionFailed Lzma.LzmaRetOK) =
"Operation completed successfully"