mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 23:41:23 +02:00
fix(agent): failed to parse agent proxy config: unexpected end of JSON input
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user