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.
This commit is contained in:
Ray Miller 2024-04-17 17:19:42 +01:00
parent 4ef3eca5a4
commit f09fd9a418

View file

@ -54,7 +54,12 @@ func BuildCtcCamIndex(r io.Reader) (*rtreego.Rtree, error) {
func FetchCtcCamIndex() (*rtreego.Rtree, error) { func FetchCtcCamIndex() (*rtreego.Rtree, error) {
log.Printf("Fetching %s", ctcCamWaypointsUrl) 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 { if err != nil {
return nil, fmt.Errorf("error getting %s: %v", ctcCamWaypointsUrl, err) return nil, fmt.Errorf("error getting %s: %v", ctcCamWaypointsUrl, err)
} }