fix(agent): failed to parse agent proxy config: unexpected end of JSON input

This commit is contained in:
yusing
2025-09-28 20:30:02 +08:00
parent 9d508c5950
commit 024100aa8c

View File

@@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/bytedance/sonic"
route "github.com/yusing/godoxy/internal/route/types" route "github.com/yusing/godoxy/internal/route/types"
) )
@@ -19,10 +20,7 @@ type Config struct {
func ConfigFromHeaders(h http.Header) (Config, error) { func ConfigFromHeaders(h http.Header) (Config, error) {
cfg, err := proxyConfigFromHeaders(h) cfg, err := proxyConfigFromHeaders(h)
if err != nil { if cfg.Host == "" || err != nil {
return cfg, err
}
if cfg.Host == "" {
cfg = proxyConfigFromHeadersLegacy(h) cfg = proxyConfigFromHeadersLegacy(h)
} }
return cfg, nil return cfg, nil
@@ -70,7 +68,7 @@ func (cfg *Config) SetAgentProxyConfigHeadersLegacy(h http.Header) {
func (cfg *Config) SetAgentProxyConfigHeaders(h http.Header) { func (cfg *Config) SetAgentProxyConfigHeaders(h http.Header) {
h.Set(HeaderXProxyHost, cfg.Host) h.Set(HeaderXProxyHost, cfg.Host)
h.Set(HeaderXProxyScheme, string(cfg.Scheme)) h.Set(HeaderXProxyScheme, string(cfg.Scheme))
cfgJSON, _ := json.Marshal(cfg.HTTPConfig) cfgJSON, _ := sonic.Marshal(cfg.HTTPConfig)
cfgBase64 := base64.StdEncoding.EncodeToString(cfgJSON) cfgBase64 := base64.StdEncoding.EncodeToString(cfgJSON)
h.Set(HeaderXProxyConfig, cfgBase64) h.Set(HeaderXProxyConfig, cfgBase64)
} }