From 1d7e4975992c7daaf58e300f676f8fa5c875eea0 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Mon, 1 Mar 2021 20:55:31 +0000 Subject: [PATCH] Added json configure file parsing of h2 transport --- infra/conf/transport_internet.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 69bba2f57..99a908aa4 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -13,6 +13,7 @@ import ( "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/transport/internet" "github.com/v2fly/v2ray-core/v4/transport/internet/domainsocket" + httpheader "github.com/v2fly/v2ray-core/v4/transport/internet/headers/http" "github.com/v2fly/v2ray-core/v4/transport/internet/http" "github.com/v2fly/v2ray-core/v4/transport/internet/kcp" "github.com/v2fly/v2ray-core/v4/transport/internet/quic" @@ -171,8 +172,10 @@ func (c *WebSocketConfig) Build() (proto.Message, error) { } type HTTPConfig struct { - Host *cfgcommon.StringList `json:"host"` - Path string `json:"path"` + Host *cfgcommon.StringList `json:"host"` + Path string `json:"path"` + Method string `json:"method"` + Headers map[string]*cfgcommon.StringList `json:"headers"` } // Build implements Buildable. @@ -183,6 +186,23 @@ func (c *HTTPConfig) Build() (proto.Message, error) { if c.Host != nil { config.Host = []string(*c.Host) } + if c.Method != "" { + config.Method = c.Method + } + if len(c.Headers) > 0 { + config.Header = make([]*httpheader.Header, 0, len(c.Headers)) + headerNames := sortMapKeys(c.Headers) + for _, key := range headerNames { + value := c.Headers[key] + if value == nil { + return nil, newError("empty HTTP header value: " + key).AtError() + } + config.Header = append(config.Header, &httpheader.Header{ + Name: key, + Value: append([]string(nil), (*value)...), + }) + } + } return config, nil }