From d28fcef0a79cb3547bc28d66723e1857fa38eeb2 Mon Sep 17 00:00:00 2001 From: Tracey Lesley <45711711+MrGlp@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:03:26 +0800 Subject: [PATCH] feat: default http User-Agent header (#26) --- internal/protocol/http/fetcher.go | 3 +++ pkg/base/constants.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 5bbfdb10..d53d0ae6 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -428,6 +428,9 @@ func buildRequest(ctx context.Context, req *base.Request) (httpReq *http.Request body = bytes.NewBufferString(extra.Body) } } + if _, ok := headers[base.HttpHeaderUserAgent]; !ok { + headers[base.HttpHeaderUserAgent] = []string{base.AgentName} + } if ctx != nil { httpReq, err = http.NewRequestWithContext(ctx, method, url.String(), body) diff --git a/pkg/base/constants.go b/pkg/base/constants.go index 0fc711e4..73481a28 100644 --- a/pkg/base/constants.go +++ b/pkg/base/constants.go @@ -19,6 +19,11 @@ const ( HttpHeaderContentLength = "Content-Length" HttpHeaderContentRange = "Content-Range" HttpHeaderContentDisposition = "Content-Disposition" + HttpHeaderUserAgent = "User-Agent" HttpHeaderRangeFormat = "bytes=%d-%d" ) + +const ( + AgentName = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" +)