Skip to content

Commit

Permalink
Merge pull request #76 from flynn/user-agent
Browse files Browse the repository at this point in the history
client: Add optional custom User-Agent to HTTPRemoteStore
  • Loading branch information
titanous committed Mar 13, 2015
2 parents 22a1f44 + 3576627 commit 1882ab4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/remote_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type HTTPRemoteOptions struct {
MetadataPath string
TargetsPath string
UserAgent string
}

func HTTPRemoteStore(baseURL string, opts *HTTPRemoteOptions) (RemoteStore, error) {
Expand Down Expand Up @@ -40,7 +41,14 @@ func (h *httpRemoteStore) GetTarget(name string) (io.ReadCloser, int64, error) {

func (h *httpRemoteStore) get(s string) (io.ReadCloser, int64, error) {
u := h.url(s)
res, err := http.Get(u)
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return nil, 0, err
}
if h.opts.UserAgent != "" {
req.Header.Set("User-Agent", h.opts.UserAgent)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, 0, err
}
Expand Down

0 comments on commit 1882ab4

Please sign in to comment.