|
@@ -2,6 +2,7 @@ package dynamicproxy
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
"log"
|
|
|
"net"
|
|
|
"net/http"
|
|
@@ -112,6 +113,8 @@ func (router *Router) rewriteURL(rooturl string, requestURL string) string {
|
|
|
func (h *ProxyHandler) hostRequest(w http.ResponseWriter, r *http.Request, target *ProxyEndpoint) {
|
|
|
r.Header.Set("X-Forwarded-Host", r.Host)
|
|
|
r.Header.Set("X-Forwarded-Server", "zoraxy-"+h.Parent.Option.HostUUID)
|
|
|
+
|
|
|
+ /* Load balancing */
|
|
|
selectedUpstream, err := h.Parent.loadBalancer.GetRequestUpstreamTarget(w, r, target.ActiveOrigins, target.UseStickySession)
|
|
|
if err != nil {
|
|
|
http.ServeFile(w, r, "./web/rperror.html")
|
|
@@ -119,31 +122,37 @@ func (h *ProxyHandler) hostRequest(w http.ResponseWriter, r *http.Request, targe
|
|
|
h.Parent.logRequest(r, false, 521, "subdomain-http", r.URL.Hostname())
|
|
|
return
|
|
|
}
|
|
|
- requestURL := r.URL.String()
|
|
|
- if r.Header["Upgrade"] != nil && strings.ToLower(r.Header["Upgrade"][0]) == "websocket" {
|
|
|
- //Handle WebSocket request. Forward the custom Upgrade header and rewrite origin
|
|
|
- r.Header.Set("Zr-Origin-Upgrade", "websocket")
|
|
|
- wsRedirectionEndpoint := selectedUpstream.OriginIpOrDomain
|
|
|
- if wsRedirectionEndpoint[len(wsRedirectionEndpoint)-1:] != "/" {
|
|
|
- //Append / to the end of the redirection endpoint if not exists
|
|
|
- wsRedirectionEndpoint = wsRedirectionEndpoint + "/"
|
|
|
- }
|
|
|
- if len(requestURL) > 0 && requestURL[:1] == "/" {
|
|
|
- //Remove starting / from request URL if exists
|
|
|
- requestURL = requestURL[1:]
|
|
|
- }
|
|
|
- u, _ := url.Parse("ws://" + wsRedirectionEndpoint + requestURL)
|
|
|
- if selectedUpstream.RequireTLS {
|
|
|
- u, _ = url.Parse("wss://" + wsRedirectionEndpoint + requestURL)
|
|
|
- }
|
|
|
- h.Parent.logRequest(r, true, 101, "host-websocket", selectedUpstream.OriginIpOrDomain)
|
|
|
- wspHandler := websocketproxy.NewProxy(u, websocketproxy.Options{
|
|
|
- SkipTLSValidation: selectedUpstream.SkipCertValidations,
|
|
|
- SkipOriginCheck: selectedUpstream.SkipWebSocketOriginCheck,
|
|
|
- })
|
|
|
- wspHandler.ServeHTTP(w, r)
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
+ /* WebSocket automatic proxy */
|
|
|
+ fmt.Println("Disable Auto Websocket Proxy", target.DisableAutoWebSockeyProxy)
|
|
|
+ /*
|
|
|
+ if !target.DisableAutoWebSockeyProxy {
|
|
|
+ requestURL := r.URL.String()
|
|
|
+ if r.Header["Upgrade"] != nil && strings.ToLower(r.Header["Upgrade"][0]) == "websocket" {
|
|
|
+ //Handle WebSocket request. Forward the custom Upgrade header and rewrite origin
|
|
|
+ r.Header.Set("Zr-Origin-Upgrade", "websocket")
|
|
|
+ wsRedirectionEndpoint := selectedUpstream.OriginIpOrDomain
|
|
|
+ if wsRedirectionEndpoint[len(wsRedirectionEndpoint)-1:] != "/" {
|
|
|
+ //Append / to the end of the redirection endpoint if not exists
|
|
|
+ wsRedirectionEndpoint = wsRedirectionEndpoint + "/"
|
|
|
+ }
|
|
|
+ if len(requestURL) > 0 && requestURL[:1] == "/" {
|
|
|
+ //Remove starting / from request URL if exists
|
|
|
+ requestURL = requestURL[1:]
|
|
|
+ }
|
|
|
+ u, _ := url.Parse("ws://" + wsRedirectionEndpoint + requestURL)
|
|
|
+ if selectedUpstream.RequireTLS {
|
|
|
+ u, _ = url.Parse("wss://" + wsRedirectionEndpoint + requestURL)
|
|
|
+ }
|
|
|
+ h.Parent.logRequest(r, true, 101, "host-websocket", selectedUpstream.OriginIpOrDomain)
|
|
|
+ wspHandler := websocketproxy.NewProxy(u, websocketproxy.Options{
|
|
|
+ SkipTLSValidation: selectedUpstream.SkipCertValidations,
|
|
|
+ SkipOriginCheck: selectedUpstream.SkipWebSocketOriginCheck,
|
|
|
+ })
|
|
|
+ wspHandler.ServeHTTP(w, r)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }*/
|
|
|
|
|
|
originalHostHeader := r.Host
|
|
|
if r.URL != nil {
|