diff --git a/zip_streamer/build_info.go b/zip_streamer/build_info.go new file mode 100644 index 0000000..d779b5b --- /dev/null +++ b/zip_streamer/build_info.go @@ -0,0 +1,20 @@ +package zip_streamer + +import ( + "runtime/debug" +) + +func getVcsRevision() string { + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + return "dev" + } + + for _, setting := range buildInfo.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:8] + } + } + + return "dev" +} diff --git a/zip_streamer/server.go b/zip_streamer/server.go index ed4af30..5d8a7c9 100644 --- a/zip_streamer/server.go +++ b/zip_streamer/server.go @@ -124,6 +124,7 @@ func retrieveZipDescriptorFromUrl(listfileUrl string, listfileBasicAuth string) return nil, err } req.SetBasicAuth("", listfileBasicAuth) + req.Header.Set("User-Agent", fmt.Sprintf("isic-zipstreamer/%s", getVcsRevision())) listfileResp, err := http.DefaultClient.Do(req) if err != nil { return nil, err diff --git a/zip_streamer/zip_streamer.go b/zip_streamer/zip_streamer.go index c390773..14df328 100644 --- a/zip_streamer/zip_streamer.go +++ b/zip_streamer/zip_streamer.go @@ -53,7 +53,13 @@ func retryableGet(url string) (*http.Response, error) { for i := 0; i < NUM_RETRIES; i++ { sleepDuration = time.Duration(math.Min(math.Pow(float64(2), float64(i)), float64(30))) * time.Second - resp, err := http.Get(url) + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + req.Header.Set("User-Agent", fmt.Sprintf("isic-zipstreamer/%s", getVcsRevision())) + resp, err := http.DefaultClient.Do(req) + if err != nil { time.Sleep(sleepDuration) } else if slices.Contains(retryableStatusCodes, resp.StatusCode) {