11{-# LANGUAGE PatternGuards #-}
22{-# LANGUAGE ScopedTypeVariables #-}
3+ {-# LANGUAGE OverloadedStrings #-}
34module Main (main ) where
45
5- import Network.HTTP hiding ( password )
6- import Network.Browser
6+ import Network.HTTP.Types.Header
7+ import Network.HTTP.Types.Status
78import Network.URI (URI (.. ))
89import Distribution.Client
910import Distribution.Client.Cron (cron , rethrowSignalsAsExceptions ,
@@ -26,6 +27,7 @@ import Control.Applicative as App
2627import Control.Exception
2728import Control.Monad
2829import Control.Monad.Trans
30+ import qualified Data.ByteString.Char8 as BSS
2931import qualified Data.ByteString.Lazy as BS
3032import qualified Data.Map as M
3133
@@ -878,20 +880,28 @@ uploadResults :: Verbosity -> BuildConfig -> DocInfo -> Maybe FilePath
878880uploadResults verbosity config docInfo
879881 mdocsTarballFile buildReportFile buildLogFile testLogFile coverageFile installOk =
880882 httpSession verbosity " hackage-build" version $ do
881- -- Make sure we authenticate to Hackage
882- setAuthorityGen (provideAuthInfo (bc_srcURI config)
883- (Just (bc_username config, bc_password config)))
884883 case mdocsTarballFile of
885884 Nothing -> return ()
886885 Just docsTarballFile ->
887886 putDocsTarball config docInfo docsTarballFile
888887
889888 putBuildFiles config docInfo buildReportFile buildLogFile testLogFile coverageFile installOk
890889
890+ withAuth :: BuildConfig -> Request -> Request
891+ withAuth config req =
892+ noRedirects $ applyBasicAuth (BSS. pack $ bc_username config) (BSS. pack $ bc_password config) req
893+
891894putDocsTarball :: BuildConfig -> DocInfo -> FilePath -> HttpSession ()
892- putDocsTarball config docInfo docsTarballFile =
893- requestPUTFile (docInfoDocsURI config docInfo)
894- " application/x-tar" (Just " gzip" ) docsTarballFile
895+ putDocsTarball config docInfo docsTarballFile = do
896+ body <- liftIO $ BS. readFile docsTarballFile
897+ req <- withAuth config <$> mkUploadRequest " PUT" uri mimetype mEncoding [] body
898+ runRequest req $ \ rsp -> do
899+ rsp' <- responseReadBSL rsp
900+ checkStatus uri rsp'
901+ where
902+ uri = docInfoDocsURI config docInfo
903+ mimetype = " application/x-tar"
904+ mEncoding = Just " gzip"
895905
896906putBuildFiles :: BuildConfig -> DocInfo -> Maybe FilePath
897907 -> FilePath -> Maybe FilePath -> Maybe FilePath -> Bool -> HttpSession ()
@@ -902,22 +912,17 @@ putBuildFiles config docInfo reportFile buildLogFile testLogFile coverageFile in
902912 coverageContent <- liftIO $ traverse readFile coverageFile
903913 let uri = docInfoReports config docInfo
904914 body = encode $ BR. BuildFiles reportContent (Just logContent) testContent coverageContent (not installOk)
905- setAllowRedirects False
906- (_, response) <- request Request {
907- rqURI = uri,
908- rqMethod = PUT ,
909- rqHeaders = [Header HdrContentType " application/json" ,
910- Header HdrContentLength (show (BS. length body))],
911- rqBody = body
912- }
913- case rspCode response of
914- -- TODO: fix server to not do give 303, 201 is more appropriate
915- (3 ,0 ,3 ) -> return ()
916- _ -> do checkStatus uri response
915+ let headers = [ (hAccept, BSS. pack " application/json" ) ]
916+ req <- withAuth config <$> mkUploadRequest (BSS. pack " PUT" ) uri " application/json" Nothing headers body
917+ runRequest req $ \ rsp -> do
918+ case statusCode $ responseStatus rsp of
919+ -- TODO: fix server to not do give 303, 201 is more appropriate
920+ 303 -> return ()
921+ _ -> do rsp' <- responseReadBSL rsp
922+ checkStatus uri rsp'
917923 fail " Unexpected response from server."
918924
919925
920-
921926-------------------------
922927-- Command line handling
923928-------------------------
0 commit comments