mirror of https://github.com/fatedier/frp
Allow deleting headers
parent
3920a788b4
commit
8c00ba7c79
|
@ -218,7 +218,9 @@ locations = ["/", "/pic"]
|
|||
# routeByHTTPUser = abc
|
||||
hostHeaderRewrite = "example.com"
|
||||
requestHeaders.set.x-from-where = "frp"
|
||||
requestHeaders.delete = [ "foo" ]
|
||||
responseHeaders.set.foo = "bar"
|
||||
requestHeaders.delete = [ "foo" ]
|
||||
healthCheck.type = "http"
|
||||
# frpc will send a GET http request '/status' to local http service
|
||||
# http service is alive when it return 2xx http response code
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/fatedier/frp/pkg/config/types"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
)
|
||||
|
||||
func Convert_ClientCommonConf_To_v1(conf *ClientCommonConf) *v1.ClientCommonConfig {
|
||||
|
@ -168,8 +169,8 @@ func Convert_ServerCommonConf_To_v1(conf *ServerCommonConf) *v1.ServerConfig {
|
|||
return out
|
||||
}
|
||||
|
||||
func transformHeadersFromPluginParams(params map[string]string) v1.HeaderOperations {
|
||||
out := v1.HeaderOperations{}
|
||||
func transformHeadersFromPluginParams(params map[string]string) msg.HeaderOperations {
|
||||
out := msg.HeaderOperations{}
|
||||
for k, v := range params {
|
||||
if !strings.HasPrefix(k, "plugin_header_") {
|
||||
continue
|
||||
|
@ -179,11 +180,6 @@ func transformHeadersFromPluginParams(params map[string]string) v1.HeaderOperati
|
|||
out.Set = make(map[string]string)
|
||||
}
|
||||
out.Set[k] = v
|
||||
|
||||
if out.Delete == nil {
|
||||
out.Delete = make(map[string]bool)
|
||||
}
|
||||
out.Delete[k] = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
|
|
|
@ -294,13 +294,13 @@ type HTTPProxyConfig struct {
|
|||
ProxyBaseConfig
|
||||
DomainConfig
|
||||
|
||||
Locations []string `json:"locations,omitempty"`
|
||||
HTTPUser string `json:"httpUser,omitempty"`
|
||||
HTTPPassword string `json:"httpPassword,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
ResponseHeaders HeaderOperations `json:"responseHeaders,omitempty"`
|
||||
RouteByHTTPUser string `json:"routeByHTTPUser,omitempty"`
|
||||
Locations []string `json:"locations,omitempty"`
|
||||
HTTPUser string `json:"httpUser,omitempty"`
|
||||
HTTPPassword string `json:"httpPassword,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders msg.HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
ResponseHeaders msg.HeaderOperations `json:"responseHeaders,omitempty"`
|
||||
RouteByHTTPUser string `json:"routeByHTTPUser,omitempty"`
|
||||
}
|
||||
|
||||
func (c *HTTPProxyConfig) MarshalToMsg(m *msg.NewProxy) {
|
||||
|
@ -312,8 +312,8 @@ func (c *HTTPProxyConfig) MarshalToMsg(m *msg.NewProxy) {
|
|||
m.HostHeaderRewrite = c.HostHeaderRewrite
|
||||
m.HTTPUser = c.HTTPUser
|
||||
m.HTTPPwd = c.HTTPPassword
|
||||
m.Headers = c.RequestHeaders.Set
|
||||
m.ResponseHeaders = c.ResponseHeaders.Set
|
||||
m.RequestHeaders = c.RequestHeaders
|
||||
m.ResponseHeaders = c.ResponseHeaders
|
||||
m.RouteByHTTPUser = c.RouteByHTTPUser
|
||||
}
|
||||
|
||||
|
@ -326,8 +326,8 @@ func (c *HTTPProxyConfig) UnmarshalFromMsg(m *msg.NewProxy) {
|
|||
c.HostHeaderRewrite = m.HostHeaderRewrite
|
||||
c.HTTPUser = m.HTTPUser
|
||||
c.HTTPPassword = m.HTTPPwd
|
||||
c.RequestHeaders.Set = m.Headers
|
||||
c.ResponseHeaders.Set = m.ResponseHeaders
|
||||
c.RequestHeaders = m.RequestHeaders
|
||||
c.ResponseHeaders = m.ResponseHeaders
|
||||
c.RouteByHTTPUser = m.RouteByHTTPUser
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
"github.com/fatedier/frp/pkg/util/util"
|
||||
)
|
||||
|
||||
|
@ -101,10 +102,10 @@ func (c *TypedClientPluginOptions) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
type HTTP2HTTPSPluginOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders msg.HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
}
|
||||
|
||||
func (o *HTTP2HTTPSPluginOptions) Complete() {}
|
||||
|
@ -118,13 +119,13 @@ type HTTPProxyPluginOptions struct {
|
|||
func (o *HTTPProxyPluginOptions) Complete() {}
|
||||
|
||||
type HTTPS2HTTPPluginOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
EnableHTTP2 *bool `json:"enableHTTP2,omitempty"`
|
||||
CrtPath string `json:"crtPath,omitempty"`
|
||||
KeyPath string `json:"keyPath,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders msg.HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
EnableHTTP2 *bool `json:"enableHTTP2,omitempty"`
|
||||
CrtPath string `json:"crtPath,omitempty"`
|
||||
KeyPath string `json:"keyPath,omitempty"`
|
||||
}
|
||||
|
||||
func (o *HTTPS2HTTPPluginOptions) Complete() {
|
||||
|
@ -132,13 +133,13 @@ func (o *HTTPS2HTTPPluginOptions) Complete() {
|
|||
}
|
||||
|
||||
type HTTPS2HTTPSPluginOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
EnableHTTP2 *bool `json:"enableHTTP2,omitempty"`
|
||||
CrtPath string `json:"crtPath,omitempty"`
|
||||
KeyPath string `json:"keyPath,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders msg.HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
EnableHTTP2 *bool `json:"enableHTTP2,omitempty"`
|
||||
CrtPath string `json:"crtPath,omitempty"`
|
||||
KeyPath string `json:"keyPath,omitempty"`
|
||||
}
|
||||
|
||||
func (o *HTTPS2HTTPSPluginOptions) Complete() {
|
||||
|
@ -146,10 +147,10 @@ func (o *HTTPS2HTTPSPluginOptions) Complete() {
|
|||
}
|
||||
|
||||
type HTTP2HTTPPluginOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
LocalAddr string `json:"localAddr,omitempty"`
|
||||
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
|
||||
RequestHeaders msg.HeaderOperations `json:"requestHeaders,omitempty"`
|
||||
}
|
||||
|
||||
func (o *HTTP2HTTPPluginOptions) Complete() {}
|
||||
|
|
|
@ -19,6 +19,12 @@ import (
|
|||
"reflect"
|
||||
)
|
||||
|
||||
// HeaderOperations represents operations to be performed on HTTP headers
|
||||
type HeaderOperations struct {
|
||||
Set map[string]string `json:"set,omitempty"`
|
||||
Delete []string `json:"delete,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
TypeLogin = 'o'
|
||||
TypeLoginResp = '1'
|
||||
|
@ -114,15 +120,15 @@ type NewProxy struct {
|
|||
RemotePort int `json:"remote_port,omitempty"`
|
||||
|
||||
// http and https only
|
||||
CustomDomains []string `json:"custom_domains,omitempty"`
|
||||
SubDomain string `json:"subdomain,omitempty"`
|
||||
Locations []string `json:"locations,omitempty"`
|
||||
HTTPUser string `json:"http_user,omitempty"`
|
||||
HTTPPwd string `json:"http_pwd,omitempty"`
|
||||
HostHeaderRewrite string `json:"host_header_rewrite,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
ResponseHeaders map[string]string `json:"response_headers,omitempty"`
|
||||
RouteByHTTPUser string `json:"route_by_http_user,omitempty"`
|
||||
CustomDomains []string `json:"custom_domains,omitempty"`
|
||||
SubDomain string `json:"subdomain,omitempty"`
|
||||
Locations []string `json:"locations,omitempty"`
|
||||
HTTPUser string `json:"http_user,omitempty"`
|
||||
HTTPPwd string `json:"http_pwd,omitempty"`
|
||||
HostHeaderRewrite string `json:"host_header_rewrite,omitempty"`
|
||||
RequestHeaders HeaderOperations `json:"request_headers,omitempty"`
|
||||
ResponseHeaders HeaderOperations `json:"response_headers,omitempty"`
|
||||
RouteByHTTPUser string `json:"route_by_http_user,omitempty"`
|
||||
|
||||
// stcp, sudp, xtcp
|
||||
Sk string `json:"sk,omitempty"`
|
||||
|
|
|
@ -61,8 +61,8 @@ func NewHTTP2HTTPPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugin
|
|||
for k, v := range p.opts.RequestHeaders.Set {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
for k, _ := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(k)
|
||||
for _, v := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(v)
|
||||
}
|
||||
},
|
||||
BufferPool: pool.NewBuffer(32 * 1024),
|
||||
|
|
|
@ -69,8 +69,8 @@ func NewHTTP2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugi
|
|||
for k, v := range p.opts.RequestHeaders.Set {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
for k, _ := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(k)
|
||||
for _, v := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(v)
|
||||
}
|
||||
},
|
||||
Transport: tr,
|
||||
|
|
|
@ -68,8 +68,8 @@ func NewHTTPS2HTTPPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugi
|
|||
for k, v := range p.opts.RequestHeaders.Set {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
for k, _ := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(k)
|
||||
for _, v := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(v)
|
||||
}
|
||||
},
|
||||
BufferPool: pool.NewBuffer(32 * 1024),
|
||||
|
|
|
@ -73,8 +73,8 @@ func NewHTTPS2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plug
|
|||
for k, v := range p.opts.RequestHeaders.Set {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
for k, _ := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(k)
|
||||
for _, v := range p.opts.RequestHeaders.Delete {
|
||||
req.Header.Del(v)
|
||||
}
|
||||
},
|
||||
Transport: tr,
|
||||
|
|
|
@ -87,9 +87,14 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|||
base64.StdEncoding.EncodeToString([]byte(rc.RouteByHTTPUser)) + "." +
|
||||
base64.StdEncoding.EncodeToString([]byte(endpoint))
|
||||
|
||||
for k, v := range rc.Headers {
|
||||
for k, v := range rc.RequestHeaders.Set {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
for _, v := range rc.RequestHeaders.Delete {
|
||||
req.Header.Del(v)
|
||||
}
|
||||
|
||||
} else {
|
||||
req.URL.Host = req.Host
|
||||
}
|
||||
|
@ -97,9 +102,13 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|||
ModifyResponse: func(r *http.Response) error {
|
||||
rc := r.Request.Context().Value(RouteConfigKey).(*RouteConfig)
|
||||
if rc != nil {
|
||||
for k, v := range rc.ResponseHeaders {
|
||||
for k, v := range rc.ResponseHeaders.Set {
|
||||
r.Header.Set(k, v)
|
||||
}
|
||||
|
||||
for _, v := range rc.ResponseHeaders.Delete {
|
||||
r.Header.Del(v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/fatedier/golib/errors"
|
||||
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
"github.com/fatedier/frp/pkg/util/log"
|
||||
netpkg "github.com/fatedier/frp/pkg/util/net"
|
||||
"github.com/fatedier/frp/pkg/util/xlog"
|
||||
|
@ -117,8 +118,8 @@ type RouteConfig struct {
|
|||
RewriteHost string
|
||||
Username string
|
||||
Password string
|
||||
Headers map[string]string
|
||||
ResponseHeaders map[string]string
|
||||
RequestHeaders msg.HeaderOperations
|
||||
ResponseHeaders msg.HeaderOperations
|
||||
RouteByHTTPUser string
|
||||
|
||||
CreateConnFn CreateConnFunc
|
||||
|
|
|
@ -57,8 +57,8 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
|
|||
routeConfig := vhost.RouteConfig{
|
||||
RewriteHost: pxy.cfg.HostHeaderRewrite,
|
||||
RouteByHTTPUser: pxy.cfg.RouteByHTTPUser,
|
||||
Headers: pxy.cfg.RequestHeaders.Set,
|
||||
ResponseHeaders: pxy.cfg.ResponseHeaders.Set,
|
||||
RequestHeaders: pxy.cfg.RequestHeaders,
|
||||
ResponseHeaders: pxy.cfg.ResponseHeaders,
|
||||
Username: pxy.cfg.HTTPUser,
|
||||
Password: pxy.cfg.HTTPPassword,
|
||||
CreateConnFn: pxy.GetRealConn,
|
||||
|
|
Loading…
Reference in New Issue