mirror of
https://github.com/fatedier/frp.git
synced 2025-07-20 04:39:26 +07:00
http: support setting headers
This commit is contained in:
@ -63,12 +63,17 @@ func NewHttpReverseProxy() *HttpReverseProxy {
|
||||
Director: func(req *http.Request) {
|
||||
req.URL.Scheme = "http"
|
||||
url := req.Context().Value("url").(string)
|
||||
host := getHostFromAddr(req.Context().Value("host").(string))
|
||||
host = rp.GetRealHost(host, url)
|
||||
oldHost := getHostFromAddr(req.Context().Value("host").(string))
|
||||
host := rp.GetRealHost(oldHost, url)
|
||||
if host != "" {
|
||||
req.Host = host
|
||||
}
|
||||
req.URL.Host = req.Host
|
||||
|
||||
headers := rp.GetHeaders(oldHost, url)
|
||||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
},
|
||||
Transport: &http.Transport{
|
||||
ResponseHeaderTimeout: responseHeaderTimeout,
|
||||
@ -117,6 +122,14 @@ func (rp *HttpReverseProxy) GetRealHost(domain string, location string) (host st
|
||||
return
|
||||
}
|
||||
|
||||
func (rp *HttpReverseProxy) GetHeaders(domain string, location string) (headers map[string]string) {
|
||||
vr, ok := rp.getVhost(domain, location)
|
||||
if ok {
|
||||
headers = vr.payload.(*VhostRouteConfig).Headers
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rp *HttpReverseProxy) CreateConnection(domain string, location string) (net.Conn, error) {
|
||||
vr, ok := rp.getVhost(domain, location)
|
||||
if ok {
|
||||
|
@ -59,6 +59,7 @@ type VhostRouteConfig struct {
|
||||
RewriteHost string
|
||||
Username string
|
||||
Password string
|
||||
Headers map[string]string
|
||||
|
||||
CreateConnFn CreateConnFunc
|
||||
}
|
||||
|
Reference in New Issue
Block a user