Skip to content

Commit

Permalink
Merge pull request #32 from brandon-leapyear/chinn/support-basic-auth
Browse files Browse the repository at this point in the history
Support basic auth
  • Loading branch information
snoyberg authored Mar 26, 2021
2 parents 0a04a97 + edbd887 commit c7923fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v0.5.1.5
* Switch back to hackage.haskell.org [#30](https://github.com/commercialhaskell/pantry/pull/30)
* Pass through basic auth credentials specified in URLs [#32](https://github.com/commercialhaskell/pantry/pull/32)

## v0.5.1.4

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pantry
version: 0.5.1.4
version: 0.5.1.5
synopsis: Content addressable Haskell package management
description: Please see the README on Github at <https://github.com/commercialhaskell/pantry#readme>
category: Development
Expand Down
17 changes: 10 additions & 7 deletions src/Hackage/Security/Client/Repository/HttpLib/HttpClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
-- Taken from
-- https://github.com/well-typed/hackage-security/tree/master/hackage-security-http-client
-- to avoid extra dependencies

-- Adapted from `hackage-security-http-client` to use our own
-- `Pantry.HTTP` implementation
module Hackage.Security.Client.Repository.HttpLib.HttpClient (
httpLib
) where
Expand Down Expand Up @@ -107,13 +107,16 @@ setRange from to =
setRequestHeaders :: [HttpRequestHeader]
-> HTTP.Request -> HTTP.Request
setRequestHeaders opts =
HTTP.setRequestHeaders (trOpt disallowCompressionByDefault opts)
setRequestHeaders' (trOpt disallowCompressionByDefault opts)
where
setRequestHeaders' :: [HTTP.Header] -> HTTP.Request -> HTTP.Request
setRequestHeaders' = foldr (\(name, val) f -> f . HTTP.setRequestHeader name [val]) id

trOpt :: [(HTTP.HeaderName, [ByteString])]
-> [HttpRequestHeader]
-> [HTTP.Header]
trOpt acc [] =
concatMap finalizeHeader acc
map finalizeHeader acc
trOpt acc (HttpRequestMaxAge0:os) =
trOpt (insert HTTP.hCacheControl ["max-age=0"] acc) os
trOpt acc (HttpRequestNoTransform:os) =
Expand All @@ -128,8 +131,8 @@ setRequestHeaders opts =
--
-- TODO: Right we we just comma-separate all of them.
finalizeHeader :: (HTTP.HeaderName, [ByteString])
-> [HTTP.Header]
finalizeHeader (name, strs) = [(name, BS.intercalate ", " (reverse strs))]
-> HTTP.Header
finalizeHeader (name, strs) = (name, BS.intercalate ", " (reverse strs))

insert :: Eq a => a -> [b] -> [(a, [b])] -> [(a, [b])]
insert _ _ [] = []
Expand Down
3 changes: 1 addition & 2 deletions src/Pantry/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import Network.HTTP.Simple as Export (HttpException (..),
getResponseBody,
getResponseHeaders,
getResponseStatus,
setRequestHeader,
setRequestHeaders)
setRequestHeader)
import qualified Network.HTTP.Simple as HTTP hiding (withResponse)
import Network.HTTP.Types as Export (Header, HeaderName,
Status, hCacheControl,
Expand Down

0 comments on commit c7923fc

Please sign in to comment.