From f09fd9a418132e4e5a4741e6c4fd70dfa7e1df94 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Wed, 17 Apr 2024 17:19:42 +0100 Subject: [PATCH] Set a custom user-agent header when fetching CTC Cambridge stops data This is required because their hosting provider is returning a 503 "service unavailable" when the user agent is Go-http-client. --- pkg/cafes/ctccam.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/cafes/ctccam.go b/pkg/cafes/ctccam.go index a95c147..0f396ba 100644 --- a/pkg/cafes/ctccam.go +++ b/pkg/cafes/ctccam.go @@ -54,7 +54,12 @@ func BuildCtcCamIndex(r io.Reader) (*rtreego.Rtree, error) { func FetchCtcCamIndex() (*rtreego.Rtree, error) { log.Printf("Fetching %s", ctcCamWaypointsUrl) - res, err := http.Get(ctcCamWaypointsUrl) + req, err := http.NewRequest(http.MethodGet, ctcCamWaypointsUrl, nil) + if err != nil { + return nil, fmt.Errorf("error constructing waypoints request: %v", err) + } + req.Header.Set("User-Agent", "gpx-utils") + res, err := http.DefaultClient.Do(req) if err != nil { return nil, fmt.Errorf("error getting %s: %v", ctcCamWaypointsUrl, err) }