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 DeriveDataTypeable #-}
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
----------------------------------------------------------------------
-- |
-- Module: Main
-- Description:
--
--
--
----------------------------------------------------------------------
module Main module Main
( main ( main
) )

View File

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

View File

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

View File

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