mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-22 14:23:30 +01:00
- move filelocker logic into dedicated subpackage - consistent useragent in requests Reviewed-on: https://gitea.com/gitea/tea/pulls/888 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
39 lines
899 B
Go
39 lines
899 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package httputil
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"runtime"
|
|
|
|
"code.gitea.io/tea/modules/version"
|
|
)
|
|
|
|
// UserAgent returns the standard User-Agent string for tea.
|
|
func UserAgent() string {
|
|
ua := fmt.Sprintf("tea/%s (%s/%s)", version.Version, runtime.GOOS, runtime.GOARCH)
|
|
if version.SDK != "" {
|
|
ua += fmt.Sprintf(" go-sdk/%s", version.SDK)
|
|
}
|
|
return ua
|
|
}
|
|
|
|
// WrapTransport wraps an http.RoundTripper to add the User-Agent header.
|
|
func WrapTransport(base http.RoundTripper) http.RoundTripper {
|
|
if base == nil {
|
|
base = http.DefaultTransport
|
|
}
|
|
return &userAgentTransport{base: base}
|
|
}
|
|
|
|
type userAgentTransport struct {
|
|
base http.RoundTripper
|
|
}
|
|
|
|
func (t *userAgentTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
req.Header.Set("User-Agent", UserAgent())
|
|
return t.base.RoundTrip(req)
|
|
}
|