Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
cmd/tier: set Accept to application/json on push (#216)
Browse files Browse the repository at this point in the history
This sets the accept header to application/json to hint to servers
capable of responding in many format, to only respond to us with JSON.

This will also follow redirects.
  • Loading branch information
bmizerany committed Jan 12, 2023
1 parent dad376f commit 0896352
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/tier/tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func runTier(cmd string, args []string) (err error) {
pj = fs.Arg(0)
}

f, err := fileOrStdin(pj)
f, err := fileOrStdin(ctx, pj)
if err != nil {
return err
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func runTier(cmd string, args []string) (err error) {
}
}

func fileOrStdin(fname string) (io.ReadCloser, error) {
func fileOrStdin(ctx context.Context, fname string) (io.ReadCloser, error) {
if fname == "" {
return nil, errUsage
}
Expand All @@ -442,7 +442,12 @@ func fileOrStdin(fname string) (io.ReadCloser, error) {
}
u, err := url.Parse(fname)
if err == nil && (u.Scheme == "http" || u.Scheme == "https") {
res, err := http.Get(fname)
r, err := http.NewRequestWithContext(ctx, "GET", fname, nil)
if err != nil {
return nil, err
}
r.Header.Set("Accept", "application/json")
res, err := http.DefaultClient.Do(r)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0896352

Please sign in to comment.