From 3cb46f1bacbb62678b5e14332f55e2e9c9d40b07 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:58:48 +0100 Subject: [PATCH] Send an identifiable user-agent. --- main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b350d73..83a42e6 100644 --- a/main.go +++ b/main.go @@ -61,7 +61,12 @@ var client = http.Client{ } func testUrl(url string) (*http.Response, error) { - resp, err := client.Get(url) + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + req.Header.Set("User-Agent", "Piped-Instances-API/(https://github.com/TeamPiped/instances-api)") + resp, err := client.Do(req) if err != nil { return resp, err } @@ -248,7 +253,13 @@ func monitorInstances() { // do forever for { // send a request to get markdown from GitHub - resp, err := http.Get("https://raw.githubusercontent.com/wiki/TeamPiped/Piped-Frontend/Instances.md") + req, err := http.NewRequest("GET", "https://raw.githubusercontent.com/wiki/TeamPiped/Piped-Frontend/Instances.md", nil) + if err != nil { + log.Print(err) + continue + } + req.Header.Set("User-Agent", "Piped-Instances-API/(https://github.com/TeamPiped/instances-api)") + resp, err := client.Do(req) if err != nil { log.Print(err) continue