Skip to content

Commit

Permalink
Fix failing verifiedDownload for hackage
Browse files Browse the repository at this point in the history
Appears they have changed their Content-MD5 header
  • Loading branch information
borsboom committed May 31, 2016
1 parent 70e3bff commit 311b858
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Network/HTTP/Download/Verified.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Control.Monad.Reader
import Control.Retry (recovering,limitRetries,RetryPolicy,constantDelay)
import "cryptohash" Crypto.Hash
import Crypto.Hash.Conduit (sinkHash)
import Data.Byteable (toBytes)
import Data.ByteString (ByteString)
import Data.ByteString.Char8 (readInteger)
import Data.Conduit
Expand Down Expand Up @@ -115,7 +116,7 @@ instance Show VerifiedDownloadException where
show (WrongDigest req algo expected actual) =
"Download expectation failure: content hash (" ++ algo ++ ")\n"
++ "Expected: " ++ displayCheckHexDigest expected ++ "\n"
++ "Actual: " ++ actual ++ "\n"
++ "Actual: " ++ show actual ++ "\n"
++ "For: " ++ show (getUri req)

instance Exception VerifiedDownloadException
Expand All @@ -138,8 +139,7 @@ displayCheckHexDigest :: CheckHexDigest -> String
displayCheckHexDigest (CheckHexDigestString s) = s ++ " (String)"
displayCheckHexDigest (CheckHexDigestByteString s) = displayByteString s ++ " (ByteString)"
displayCheckHexDigest (CheckHexDigestHeader h) =
displayByteString (B64.decodeLenient h) ++ " (Header. unencoded: "
++ displayByteString h ++ ")"
show (B64.decodeLenient h) ++ " (Header. unencoded: " ++ show h ++ ")"


-- | Make sure that the hash digest for a finite stream of bytes
Expand All @@ -154,11 +154,13 @@ sinkCheckHash req HashCheck{..} = do
digest <- sinkHashUsing hashCheckAlgorithm
let actualDigestString = show digest
let actualDigestHexByteString = digestToHexByteString digest
let actualDigestBytes = toBytes digest

let passedCheck = case hashCheckHexDigest of
CheckHexDigestString s -> s == actualDigestString
CheckHexDigestByteString b -> b == actualDigestHexByteString
CheckHexDigestHeader b -> B64.decodeLenient b == actualDigestHexByteString
|| B64.decodeLenient b == actualDigestBytes
-- A hack to allow hackage tarballs to download.
-- They should really base64-encode their md5 header as per rfc2616#sec14.15.
-- https://github.com/commercialhaskell/stack/issues/240
Expand Down

0 comments on commit 311b858

Please sign in to comment.