Change bot user-agent

main
Leonid Maslakov 4 months ago
parent 3d6dc20295
commit c5f6cc5c7b

@ -1,8 +1,10 @@
NAME = lenmonitor
FULL_NAME = LenMonitor
MAIN_GO = ./cmd/*.go
export GOMODULE111=on
LDFLAGS = -w -s -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')"
VERSION = $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
LDFLAGS = -w -s -X "main.Version=$(VERSION)" -X "internal/tester.UserAgent=$(FULL_NAME)/$(VERSION)"
.PHONY: all fmt clean

@ -22,8 +22,11 @@ import (
"errors"
"net"
"net/http"
"time"
)
var UserAgent = "LenMonitor/unknown"
var (
ErrFailedConnect = errors.New("tester: failed to connect to server via HTTP or HTTPS")
ErrNot200 = errors.New("tester: HTTP server response code is different from 200 when requesting HTTP and HTTPS")
@ -69,10 +72,18 @@ func getHttpAndHttps(domain string, path string) (*http.Response, bool, bool, bo
// Disable redirect
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
},
Timeout: 5 * time.Second,
}
// Try HTTP
respHttp, err := client.Get("http://" + domain + path)
reqHttp, err := http.NewRequest("GET", "http://"+domain+path, nil)
if err != nil {
return nil, domainIsIP, httpSupport, httpsSupport, httpToHttpsRedirect, false, err
}
reqHttp.Header.Set("User-Agent", UserAgent)
respHttp, err := client.Do(reqHttp)
if err != nil {
httpSupport = false
@ -86,7 +97,13 @@ func getHttpAndHttps(domain string, path string) (*http.Response, bool, bool, bo
}
// Try HTTPS
respHttps, err := client.Get("https://" + domain + path)
reqHttps, err := http.NewRequest("GET", "https://"+domain+path, nil)
if err != nil {
return nil, domainIsIP, httpSupport, httpsSupport, httpToHttpsRedirect, false, err
}
reqHttps.Header.Set("User-Agent", UserAgent)
respHttps, err := client.Do(reqHttps)
if err != nil {
httpsSupport = false

Loading…
Cancel
Save