mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-08-07 21:58:29 +02:00
Updates v2.6.1
+ Added reverse proxy TLS skip verification + Added basic auth + Edit proxy settings + Whitelist + TCP Proxy (experimental) + Info (Utilities page)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
package websocketproxy
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -46,16 +47,19 @@ type WebsocketProxy struct {
|
||||
// If nil, DefaultDialer is used.
|
||||
Dialer *websocket.Dialer
|
||||
|
||||
Verbal bool
|
||||
Verbal bool
|
||||
SkipTlsValidation bool
|
||||
}
|
||||
|
||||
// ProxyHandler returns a new http.Handler interface that reverse proxies the
|
||||
// request to the given target.
|
||||
func ProxyHandler(target *url.URL) http.Handler { return NewProxy(target) }
|
||||
func ProxyHandler(target *url.URL, skipTlsValidation bool) http.Handler {
|
||||
return NewProxy(target, skipTlsValidation)
|
||||
}
|
||||
|
||||
// NewProxy returns a new Websocket reverse proxy that rewrites the
|
||||
// URL's to the scheme, host and base path provider in target.
|
||||
func NewProxy(target *url.URL) *WebsocketProxy {
|
||||
func NewProxy(target *url.URL, skipTlsValidation bool) *WebsocketProxy {
|
||||
backend := func(r *http.Request) *url.URL {
|
||||
// Shallow copy
|
||||
u := *target
|
||||
@@ -64,7 +68,7 @@ func NewProxy(target *url.URL) *WebsocketProxy {
|
||||
u.RawQuery = r.URL.RawQuery
|
||||
return &u
|
||||
}
|
||||
return &WebsocketProxy{Backend: backend, Verbal: false}
|
||||
return &WebsocketProxy{Backend: backend, Verbal: false, SkipTlsValidation: skipTlsValidation}
|
||||
}
|
||||
|
||||
// ServeHTTP implements the http.Handler that proxies WebSocket connections.
|
||||
@@ -84,7 +88,15 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
dialer := w.Dialer
|
||||
if w.Dialer == nil {
|
||||
dialer = DefaultDialer
|
||||
if w.SkipTlsValidation {
|
||||
//Disable TLS secure check if target allow skip verification
|
||||
bypassDialer := websocket.DefaultDialer
|
||||
bypassDialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
dialer = bypassDialer
|
||||
} else {
|
||||
//Just use the default dialer come with gorilla websocket
|
||||
dialer = DefaultDialer
|
||||
}
|
||||
}
|
||||
|
||||
// Pass headers from the incoming request to the dialer to forward them to
|
||||
|
@@ -28,7 +28,7 @@ func TestProxy(t *testing.T) {
|
||||
}
|
||||
|
||||
u, _ := url.Parse(backendURL)
|
||||
proxy := NewProxy(u)
|
||||
proxy := NewProxy(u, false)
|
||||
proxy.Upgrader = upgrader
|
||||
|
||||
mux := http.NewServeMux()
|
||||
@@ -46,7 +46,7 @@ func TestProxy(t *testing.T) {
|
||||
mux2 := http.NewServeMux()
|
||||
mux2.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Don't upgrade if original host header isn't preserved
|
||||
if r.Host != "127.0.0.1:7777" {
|
||||
if r.Host != "127.0.0.1:7777" {
|
||||
log.Printf("Host header set incorrectly. Expecting 127.0.0.1:7777 got %s", r.Host)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user