Skip to content
Browse files

Set the http user agent in each client properly

  • Loading branch information...
1 parent f571fce commit 20ea7916582186b40cd9c3c7a51614696d85d522 @dcoutts dcoutts committed Nov 4, 2013
Showing with 11 additions and 8 deletions.
  1. +6 −3 BuildClient.hs
  2. +4 −4 Distribution/Client.hs
  3. +1 −1 ImportClient.hs
View
9 BuildClient.hs
@@ -35,6 +35,9 @@ import System.Process
import System.IO
import System.IO.Error
+import Paths_hackage_server (version)
+
+
import Data.Aeson (eitherDecode)
data Mode = Help [String]
@@ -160,7 +163,7 @@ stats opts = do
createDirectoryIfMissing False cacheDir
(didFail, _, _) <- mkPackageFailed opts
- httpSession verbosity $ do
+ httpSession verbosity "hackage-build" version $ do
liftIO $ notice verbosity "Getting index"
infoStats verbosity (Just statsFile) =<< getDocumentationStats config didFail
where
@@ -350,7 +353,7 @@ buildOnce opts pkgs = keepGoing $ do
unless configFileExists $ prepareBuildPackages opts config
flip finally persist_failed $ do
- pkgIdsHaveDocs <- httpSession verbosity $
+ pkgIdsHaveDocs <- httpSession verbosity "hackage-build" version $
getDocumentationStats config has_failed
infoStats verbosity Nothing pkgIdsHaveDocs
@@ -385,7 +388,7 @@ buildOnce opts pkgs = keepGoing $ do
case mTgz of
Nothing ->
liftIO $ mark_as_failed (docInfoPackage docInfo)
- Just docs_tgz -> httpSession verbosity $ do
+ Just docs_tgz -> httpSession verbosity "hackage-build" version $ do
-- Make sure we authenticate to Hackage
setAuthorityGen $ provideAuthInfo (bc_srcURI config)
$ Just (bc_username config, bc_password config)
View
8 Distribution/Client.hs
@@ -35,6 +35,7 @@ import Distribution.Server.Util.Index as PackageIndex (read)
import Distribution.Server.Util.Merge
import Distribution.Server.Util.Parse (unpackUTF8)
import Distribution.Package
+import Distribution.Version
import Distribution.Verbosity
import Distribution.Simple.Utils
import Distribution.Text
@@ -58,7 +59,6 @@ import System.FilePath
import System.Directory
import qualified System.FilePath.Posix as Posix
-import Paths_hackage_server (version)
-------------------------
-- Command line handling
@@ -229,10 +229,10 @@ uriHostName = fmap uriRegName . uriAuthority
type HttpSession a = BrowserAction (HandleStream ByteString) a
-httpSession :: Verbosity -> HttpSession a -> IO a
-httpSession verbosity action =
+httpSession :: Verbosity -> String -> Version -> HttpSession a -> IO a
+httpSession verbosity agent version action =
browse $ do
- setUserAgent ("hackage-mirror/" ++ display version)
+ setUserAgent (agent ++ "/" ++ display version)
setErrHandler die
setOutHandler (debug verbosity)
setAllowBasicAuth True
View
2 ImportClient.hs
@@ -245,7 +245,7 @@ importAccounts jobs htpasswdFile makeUploader baseURI = do
=<< readFile htpasswdFile
concForM_ jobs htpasswdDb $ \tasks ->
- httpSession $ do
+ httpSession "hackage-import" version $ do
setAuthorityFromURI baseURI
tasks $ \(username, mPasswdhash) ->
putUserAccount baseURI username mPasswdhash makeUploader

0 comments on commit 20ea791

Please sign in to comment.
Something went wrong with that request. Please try again.