Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support basic auth #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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