Skip to content

Commit

Permalink
Make default user agent constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Apr 22, 2024
1 parent cf3821c commit eb48c85
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
"go.opentelemetry.io/otel/trace"
)

// defaultUserAgent is sent with requests if no other user agent has been supplied.
const defaultUserAgent = "go-eth2-client/0.21.2"

// post sends an HTTP post request and returns the body.
func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io.Reader, error) {
// #nosec G404
Expand All @@ -59,7 +62,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
if req.Header.Get("User-Agent") == "" {
req.Header.Set("User-Agent", "go-eth2-client/0.21.1")
req.Header.Set("User-Agent", defaultUserAgent)
}

resp, err := s.client.Do(req)
Expand Down Expand Up @@ -149,7 +152,7 @@ func (s *Service) post2(ctx context.Context,
req.Header.Set(k, v)
}
if req.Header.Get("User-Agent") == "" {
req.Header.Set("User-Agent", "go-eth2-client/0.21.1")
req.Header.Set("User-Agent", defaultUserAgent)
}

resp, err := s.client.Do(req)
Expand Down

0 comments on commit eb48c85

Please sign in to comment.