Allow HTTP Client to be supplied

This will allow for more customized behavior than is currently
available.

Change-Id: I45e1bfe66469148c5bd6d228af0a7002d8f048a4
diff --git a/client/client_test.go b/client/client_test.go
index d715ea7..8d39767 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -10,7 +10,7 @@
 	"testing"
 	"time"
 
-	"github.com/flynn/go-tuf"
+	tuf "github.com/flynn/go-tuf"
 	"github.com/flynn/go-tuf/data"
 	"github.com/flynn/go-tuf/util"
 	"github.com/flynn/go-tuf/verify"
@@ -723,7 +723,7 @@
 		repo := generateRepoFS(c, filepath.Join(tmp, dir), targetFiles, consistentSnapshot)
 
 		// initialize a client
-		remote, err := HTTPRemoteStore(fmt.Sprintf("http://%s/%s/repository", addr, dir), nil)
+		remote, err := HTTPRemoteStore(fmt.Sprintf("http://%s/%s/repository", addr, dir), nil, nil)
 		c.Assert(err, IsNil)
 		client := NewClient(MemoryLocalStore(), remote)
 		rootKeys, err := repo.RootKeys()
diff --git a/client/interop_test.go b/client/interop_test.go
index 86ab8c3..8b6a107 100644
--- a/client/interop_test.go
+++ b/client/interop_test.go
@@ -12,7 +12,7 @@
 	"path/filepath"
 	"strings"
 
-	"github.com/flynn/go-tuf"
+	tuf "github.com/flynn/go-tuf"
 	"github.com/flynn/go-tuf/data"
 	"github.com/flynn/go-tuf/util"
 	"golang.org/x/crypto/ed25519"
@@ -40,6 +40,7 @@
 		remote, err := HTTPRemoteStore(
 			fmt.Sprintf("http://%s/%s/repository", addr, dir),
 			&HTTPRemoteOptions{MetadataPath: "metadata", TargetsPath: "targets"},
+			nil,
 		)
 		c.Assert(err, IsNil)
 
diff --git a/client/remote_store.go b/client/remote_store.go
index 4e21c42..17a63fc 100644
--- a/client/remote_store.go
+++ b/client/remote_store.go
@@ -28,7 +28,7 @@
 	Total: 10 * time.Second,
 }
 
-func HTTPRemoteStore(baseURL string, opts *HTTPRemoteOptions) (RemoteStore, error) {
+func HTTPRemoteStore(baseURL string, opts *HTTPRemoteOptions, client *http.Client) (RemoteStore, error) {
 	if !strings.HasPrefix(baseURL, "http") {
 		return nil, ErrInvalidURL{baseURL}
 	}
@@ -38,12 +38,16 @@
 	if opts.TargetsPath == "" {
 		opts.TargetsPath = "targets"
 	}
-	return &httpRemoteStore{baseURL, opts}, nil
+	if client == nil {
+		client = http.DefaultClient
+	}
+	return &httpRemoteStore{baseURL, opts, client}, nil
 }
 
 type httpRemoteStore struct {
 	baseURL string
 	opts    *HTTPRemoteOptions
+	cli     *http.Client
 }
 
 func (h *httpRemoteStore) GetMeta(name string) (io.ReadCloser, int64, error) {
@@ -66,13 +70,13 @@
 	var res *http.Response
 	if r := h.opts.Retries; r != nil {
 		for start := time.Now(); time.Since(start) < r.Total; time.Sleep(r.Delay) {
-			res, err = http.DefaultClient.Do(req)
+			res, err = h.cli.Do(req)
 			if err == nil && (res.StatusCode < 500 || res.StatusCode > 599) {
 				break
 			}
 		}
 	} else {
-		res, err = http.DefaultClient.Do(req)
+		res, err = h.cli.Do(req)
 	}
 	if err != nil {
 		return nil, 0, err
diff --git a/cmd/tuf-client/main.go b/cmd/tuf-client/main.go
index 5da2ee5..0d81a7b 100644
--- a/cmd/tuf-client/main.go
+++ b/cmd/tuf-client/main.go
@@ -4,7 +4,7 @@
 	"fmt"
 	"log"
 
-	"github.com/flynn/go-docopt"
+	docopt "github.com/flynn/go-docopt"
 	tuf "github.com/flynn/go-tuf/client"
 )
 
@@ -88,7 +88,7 @@
 	if err != nil {
 		return nil, err
 	}
-	remote, err := tuf.HTTPRemoteStore(args.String["<url>"], nil)
+	remote, err := tuf.HTTPRemoteStore(args.String["<url>"], nil, nil)
 	if err != nil {
 		return nil, err
 	}