From f6735cb872326d74cfe4fd7c899abfdd0947c649 Mon Sep 17 00:00:00 2001 From: Juan Pedro Villa Isaza Date: Sat, 10 Sep 2016 17:23:32 -0500 Subject: [PATCH] Replace HTTP with http-conduit (close #9) --- Main.hs | 9 +++++++++ licensor.cabal | 47 +++++++++++++++++++++++++++++++---------------- src/Licensor.hs | 38 +++++++++++++++++++++++++------------- stack.yaml | 2 +- 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Main.hs b/Main.hs index 6aa895c..5132a9f 100644 --- a/Main.hs +++ b/Main.hs @@ -1,6 +1,15 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE RecordWildCards #-} +---------------------------------------------------------------------- +-- | +-- Module: Main +-- Description: +-- +-- +-- +---------------------------------------------------------------------- + module Main ( main ) diff --git a/licensor.cabal b/licensor.cabal index 75a3289..51c9ca9 100644 --- a/licensor.cabal +++ b/licensor.cabal @@ -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 -maintainer: Juan Pedro Villa Isaza -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 +maintainer: 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 + +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 diff --git a/src/Licensor.hs b/src/Licensor.hs index 8bebf7d..4acc487 100644 --- a/src/Licensor.hs +++ b/src/Licensor.hs @@ -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 diff --git a/stack.yaml b/stack.yaml index 3334532..84d3b33 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1 +1 @@ -resolver: lts-6.11 +resolver: lts-6.16