http: increase default response header timeout to 60s, add option to customize it, schema update

This commit is contained in:
yusing
2025-01-30 00:41:03 +08:00
parent d9b6b82f07
commit dfc634a362
18 changed files with 96 additions and 28 deletions

View File

@@ -44,11 +44,15 @@ type (
// var globalMux = http.NewServeMux() // TODO: support regex subdomain matching.
func NewHTTPRoute(entry *entry.ReverseProxyEntry) (impl, E.Error) {
var trans *http.Transport
if entry.Raw.NoTLSVerify {
trans := gphttp.DefaultTransport
httpConfig := entry.Raw.HTTPConfig
if httpConfig.NoTLSVerify {
trans = gphttp.DefaultTransportNoTLS
} else {
trans = gphttp.DefaultTransport
}
if httpConfig.ResponseHeaderTimeout > 0 {
trans = trans.Clone()
trans.ResponseHeaderTimeout = httpConfig.ResponseHeaderTimeout
}
service := entry.TargetName()

View File

@@ -0,0 +1,10 @@
package types
import (
"time"
)
type HTTPConfig struct {
NoTLSVerify bool `json:"no_tls_verify,omitempty"`
ResponseHeaderTimeout time.Duration `json:"response_header_timeout,omitempty"`
}

View File

@@ -0,0 +1,47 @@
package types
import (
"testing"
"time"
"github.com/yusing/go-proxy/internal/utils"
. "github.com/yusing/go-proxy/internal/utils/testing"
)
func TestHTTPConfigDeserialize(t *testing.T) {
tests := []struct {
name string
input map[string]any
expected HTTPConfig
}{
{
name: "no_tls_verify",
input: map[string]any{
"no_tls_verify": "true",
},
expected: HTTPConfig{
NoTLSVerify: true,
},
},
{
name: "response_header_timeout",
input: map[string]any{
"response_header_timeout": "1s",
},
expected: HTTPConfig{
ResponseHeaderTimeout: 1 * time.Second,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := RawEntry{}
err := utils.Deserialize(tt.input, &cfg)
if err != nil {
ExpectNoError(t, err)
}
ExpectDeepEqual(t, cfg.HTTPConfig, &tt.expected)
})
}
}

View File

@@ -25,11 +25,12 @@ type (
// raw entry object before validation
// loaded from docker labels or yaml file
Alias string `json:"alias"`
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port string `json:"port,omitempty"`
NoTLSVerify bool `json:"no_tls_verify,omitempty"`
Alias string `json:"alias"`
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Port string `json:"port,omitempty"`
HTTPConfig
PathPatterns []string `json:"path_patterns,omitempty"`
Rules rules.Rules `json:"rules,omitempty" validate:"omitempty,unique=Name"`
HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty"`