Replace HTTP with http-conduit (close #9)

This commit is contained in:
Juan Pedro Villa Isaza 2016-09-10 17:23:32 -05:00
parent 2558a0579e
commit f6735cb872
4 changed files with 66 additions and 30 deletions

View File

@ -1,6 +1,15 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE RecordWildCards #-}
----------------------------------------------------------------------
-- |
-- Module: Main
-- Description:
--
--
--
----------------------------------------------------------------------
module Main
( main
)

View File

@ -1,18 +1,30 @@
name: licensor
version: 0.1.0
synopsis: A license compatibility helper
description: A license compatibility helper.
homepage: https://github.com/jpvillaisaza/licensor
bug-reports: https://github.com/jpvillaisaza/licensor/issues
license: MIT
license-file: LICENSE.md
author: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
maintainer: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
copyright: 2016 Juan Pedro Villa Isaza
category: Distribution
name: licensor
version: 0.1.0
build-type: Simple
cabal-version: >= 1.21
license: MIT
license-file: LICENSE.md
copyright: 2016 Juan Pedro Villa Isaza
author: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
maintainer: Juan Pedro Villa Isaza <jpvillaisaza@gmail.com>
stability: Experimental
homepage: https://github.com/jpvillaisaza/licensor
bug-reports: https://github.com/jpvillaisaza/licensor/issues
synopsis: A license compatibility helper
description: A license compatibility helper.
category: Distribution
tested-with: GHC == 7.10.3, GHC == 8.0.1
extra-source-files: README.md
build-type: Simple
cabal-version: >= 1.10
library
hs-source-dirs:
@ -22,17 +34,19 @@ library
other-modules:
Paths_licensor
build-depends:
base >= 4.8 && < 5.0
base >= 4.8 && < 4.10
, bytestring
, Cabal >= 1.22 && < 1.25
, containers
, directory
, HTTP >= 4000.3 && < 4000.4
, http-conduit >= 2.1 && < 2.3
, process
default-language:
Haskell2010
ghc-options:
-Wall
executable licensor
main-is:
Main.hs
@ -47,6 +61,7 @@ executable licensor
ghc-options:
-Wall -threaded -rtsopts -with-rtsopts=-N
source-repository head
type: git
location: https://github.com/jpvillaisaza/licensor

View File

@ -2,6 +2,15 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
----------------------------------------------------------------------
-- |
-- Module: Licensor
-- Description:
--
--
--
----------------------------------------------------------------------
module Licensor
( LiLicense(..)
, LiPackage(..)
@ -12,14 +21,14 @@ module Licensor
)
where
-- licensor
import qualified Paths_licensor as Paths
-- base
import Data.Monoid ((<>))
import Data.Version (Version)
import System.IO
-- bytestring
import qualified Data.ByteString.Lazy as ByteString
-- Cabal
import Distribution.License
import Distribution.Package
@ -38,12 +47,12 @@ import qualified Data.Set as Set
-- directory
import System.Directory
-- HTTP
import Network.HTTP
( getRequest
, getResponseBody
, simpleHTTP
)
-- http-conduit
--import Network.HTTP.Client.Conduit
import Network.HTTP.Simple
-- licensor
import qualified Paths_licensor
-- process
import System.Process
@ -116,15 +125,18 @@ getPackageLicense :: PackageIdentifier -> IO LiLicense
getPackageLicense p@PackageIdentifier{..} = do
let
url =
"http://hackage.haskell.org/package/"
"GET https://hackage.haskell.org/package/"
<> display p
<> "/"
<> unPackageName pkgName
<> ".cabal"
pd <- simpleHTTP (getRequest url) >>= getResponseBody
req <- parseRequest url
pd <- fmap getResponseBody (httpLBS req)
(file, handle) <- openTempFile "/tmp" "licensor"
hClose handle
writeFile file pd
ByteString.writeFile file pd
PackageDescription{license} <- getPackageDescription file
hClose handle
removeFile file
@ -164,4 +176,4 @@ orderPackagesByLicense p =
version :: Version
version =
Paths.version
Paths_licensor.version

View File

@ -1 +1 @@
resolver: lts-6.11
resolver: lts-6.16