|
@@ -63,9 +63,9 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|
req := r.Out
|
|
req := r.Out
|
|
req.URL.Scheme = "http"
|
|
req.URL.Scheme = "http"
|
|
reqRouteInfo := req.Context().Value(RouteInfoKey).(*RequestRouteInfo)
|
|
reqRouteInfo := req.Context().Value(RouteInfoKey).(*RequestRouteInfo)
|
|
- oldHost, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
|
|
|
|
|
|
+ originalHost, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
|
|
|
|
|
|
- rc := rp.GetRouteConfig(oldHost, reqRouteInfo.URL, reqRouteInfo.HTTPUser)
|
|
|
|
|
|
+ rc := req.Context().Value(RouteConfigKey).(*RouteConfig)
|
|
if rc != nil {
|
|
if rc != nil {
|
|
if rc.RewriteHost != "" {
|
|
if rc.RewriteHost != "" {
|
|
req.Host = rc.RewriteHost
|
|
req.Host = rc.RewriteHost
|
|
@@ -77,7 +77,7 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|
endpoint, _ = rc.ChooseEndpointFn()
|
|
endpoint, _ = rc.ChooseEndpointFn()
|
|
reqRouteInfo.Endpoint = endpoint
|
|
reqRouteInfo.Endpoint = endpoint
|
|
log.Tracef("choose endpoint name [%s] for http request host [%s] path [%s] httpuser [%s]",
|
|
log.Tracef("choose endpoint name [%s] for http request host [%s] path [%s] httpuser [%s]",
|
|
- endpoint, oldHost, reqRouteInfo.URL, reqRouteInfo.HTTPUser)
|
|
|
|
|
|
+ endpoint, originalHost, reqRouteInfo.URL, reqRouteInfo.HTTPUser)
|
|
}
|
|
}
|
|
// Set {domain}.{location}.{routeByHTTPUser}.{endpoint} as URL host here to let http transport reuse connections.
|
|
// Set {domain}.{location}.{routeByHTTPUser}.{endpoint} as URL host here to let http transport reuse connections.
|
|
req.URL.Host = rc.Domain + "." +
|
|
req.URL.Host = rc.Domain + "." +
|
|
@@ -92,6 +92,15 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|
req.URL.Host = req.Host
|
|
req.URL.Host = req.Host
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ ModifyResponse: func(r *http.Response) error {
|
|
|
|
+ rc := r.Request.Context().Value(RouteConfigKey).(*RouteConfig)
|
|
|
|
+ if rc != nil {
|
|
|
|
+ for k, v := range rc.ResponseHeaders {
|
|
|
|
+ r.Header.Set(k, v)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ },
|
|
// Create a connection to one proxy routed by route policy.
|
|
// Create a connection to one proxy routed by route policy.
|
|
Transport: &http.Transport{
|
|
Transport: &http.Transport{
|
|
ResponseHeaderTimeout: rp.responseHeaderTimeout,
|
|
ResponseHeaderTimeout: rp.responseHeaderTimeout,
|
|
@@ -157,14 +166,6 @@ func (rp *HTTPReverseProxy) GetRouteConfig(domain, location, routeByHTTPUser str
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (rp *HTTPReverseProxy) GetHeaders(domain, location, routeByHTTPUser string) (headers map[string]string) {
|
|
|
|
- vr, ok := rp.getVhost(domain, location, routeByHTTPUser)
|
|
|
|
- if ok {
|
|
|
|
- headers = vr.payload.(*RouteConfig).Headers
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// CreateConnection create a new connection by route config
|
|
// CreateConnection create a new connection by route config
|
|
func (rp *HTTPReverseProxy) CreateConnection(reqRouteInfo *RequestRouteInfo, byEndpoint bool) (net.Conn, error) {
|
|
func (rp *HTTPReverseProxy) CreateConnection(reqRouteInfo *RequestRouteInfo, byEndpoint bool) (net.Conn, error) {
|
|
host, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
|
|
host, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
|
|
@@ -305,8 +306,13 @@ func (rp *HTTPReverseProxy) injectRequestInfoToCtx(req *http.Request) *http.Requ
|
|
RemoteAddr: req.RemoteAddr,
|
|
RemoteAddr: req.RemoteAddr,
|
|
URLHost: req.URL.Host,
|
|
URLHost: req.URL.Host,
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ originalHost, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
|
|
|
|
+ rc := rp.GetRouteConfig(originalHost, reqRouteInfo.URL, reqRouteInfo.HTTPUser)
|
|
|
|
+
|
|
newctx := req.Context()
|
|
newctx := req.Context()
|
|
newctx = context.WithValue(newctx, RouteInfoKey, reqRouteInfo)
|
|
newctx = context.WithValue(newctx, RouteInfoKey, reqRouteInfo)
|
|
|
|
+ newctx = context.WithValue(newctx, RouteConfigKey, rc)
|
|
return req.Clone(newctx)
|
|
return req.Clone(newctx)
|
|
}
|
|
}
|
|
|
|
|