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

client: Add optional custom User-Agent to HTTPRemoteStore #76

Merged
merged 1 commit into from
Mar 13, 2015
Merged
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
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