MSP-8995 fix review comments

This commit is contained in:
bogdanmezencev committed 2026-11-20 14:51:43 +03:00
1 parent 5fef05516b
commit 458f94cfd6
12 files changed
+28 -89

No files matched your search

-4
View File
@@ -32,7 +32,6 @@ func init() {
}
}
//nolint:gochecknoglobals
var (
codeMap = map[int]codes.Code{
http.StatusOK: codes.OK,
@@ -165,9 +164,6 @@ func (p Grpc) writeMetadata(ctx *request.Context) metadata.MD {
appAuthData, err := ctx.GetAuthData()
if err == nil {
md[grpc.SystemIdHeader] = []string{strconv.Itoa(appAuthData.SystemId)}
md[grpc.DomainIdHeader] = []string{strconv.Itoa(appAuthData.DomainId)}
md[grpc.ServiceIdHeader] = []string{strconv.Itoa(appAuthData.ServiceId)}
md[grpc.ApplicationIdHeader] = []string{strconv.Itoa(appAuthData.ApplicationId)}
encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName))
md[grpc.ApplicationNameHeader] = []string{encodedAppName}
+10 -24
View File
@@ -20,30 +20,21 @@ import (
"github.com/txix-open/isp-kit/requestid"
)
const (
httpDialTimeout = 3 * time.Second
httpDialKeepAlive = 30 * time.Second
httpMaxIdleConns = 512
httpMaxIdleConnsPerHost = 32
httpIdleConnTimeout = 60 * time.Second
httpTLSHandshakeTimeout = 5 * time.Second
)
func newHttpTransport() *http.Transport {
return &http.Transport{
var (
httpTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: defaultTransportDialContext(&net.Dialer{
Timeout: httpDialTimeout,
KeepAlive: httpDialKeepAlive,
Timeout: 3 * time.Second,
KeepAlive: 30 * time.Second,
}),
ForceAttemptHTTP2: true,
MaxIdleConns: httpMaxIdleConns,
MaxIdleConnsPerHost: httpMaxIdleConnsPerHost,
IdleConnTimeout: httpIdleConnTimeout,
TLSHandshakeTimeout: httpTLSHandshakeTimeout,
MaxIdleConns: 512,
MaxIdleConnsPerHost: 32,
IdleConnTimeout: 60 * time.Second,
TLSHandshakeTimeout: 5 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}
)
type HttpHostManager interface {
Next() (string, error)
@@ -51,7 +42,6 @@ type HttpHostManager interface {
type Http struct {
hostManager HttpHostManager
transport http.RoundTripper
skipAuth bool
timeout time.Duration
}
@@ -59,7 +49,6 @@ type Http struct {
func NewHttp(hostManager HttpHostManager, skipAuth bool, timeout time.Duration) Http {
return Http{
hostManager: hostManager,
transport: newHttpTransport(),
skipAuth: skipAuth,
timeout: timeout,
}
@@ -82,7 +71,7 @@ func (p Http) Handle(ctx *request.Context) error {
setHttpHeaders(ctx, request.Header, p.skipAuth)
reverseProxy := httputil.NewSingleHostReverseProxy(target)
reverseProxy.Transport = p.transport
reverseProxy.Transport = httpTransport
var resultError error
reverseProxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, err error) {
resultError = httperrors.New(
@@ -121,9 +110,6 @@ func setHttpHeaders(ctx *request.Context, header http.Header, skipAuth bool) {
appAuthData, err := ctx.GetAuthData()
if err == nil {
header.Set(grpc.SystemIdHeader, strconv.Itoa(appAuthData.SystemId))
header.Set(grpc.DomainIdHeader, strconv.Itoa(appAuthData.DomainId))
header.Set(grpc.ServiceIdHeader, strconv.Itoa(appAuthData.ServiceId))
header.Set(grpc.ApplicationIdHeader, strconv.Itoa(appAuthData.ApplicationId))
encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName))
header.Set(grpc.ApplicationNameHeader, encodedAppName) //nolint:canonicalheader
+3 -9
View File
@@ -13,12 +13,6 @@ import (
"isp-gate-service/request"
)
const (
wsHandshakeTimeout = 5 * time.Second
wsReadBufferSize = 1024
wsWriteBufferSize = 1024
)
type Ws struct {
hostManager HttpHostManager
skipAuth bool
@@ -52,9 +46,9 @@ func (ws Ws) Handle(ctx *request.Context) error {
setHttpHeaders(ctx, out, ws.skipAuth)
}
proxy.Upgrader = &websocket.Upgrader{
HandshakeTimeout: wsHandshakeTimeout,
ReadBufferSize: wsReadBufferSize,
WriteBufferSize: wsWriteBufferSize,
HandshakeTimeout: 5 * time.Second,
ReadBufferSize: 1024,
WriteBufferSize: 1024,
WriteBufferPool: nil,
Subprotocols: nil,
Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {