mirror of https://github.com/gorilla/websocket.git
add unit test for https proxy
This commit is contained in:
parent
2553869a29
commit
d16969baa1
|
@ -185,6 +185,47 @@ func TestProxyDial(t *testing.T) {
|
||||||
sendRecv(t, ws)
|
sendRecv(t, ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHttpsProxy(t *testing.T) {
|
||||||
|
|
||||||
|
sTLS := newTLSServer(t)
|
||||||
|
defer sTLS.Close()
|
||||||
|
s := newServer(t)
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
surlTLS, _ := url.Parse(sTLS.Server.URL)
|
||||||
|
|
||||||
|
cstDialer := cstDialer // make local copy for modification on next line.
|
||||||
|
cstDialer.Proxy = http.ProxyURL(surlTLS)
|
||||||
|
|
||||||
|
connect := false
|
||||||
|
origHandler := sTLS.Server.Config.Handler
|
||||||
|
|
||||||
|
// Capture the request Host header.
|
||||||
|
sTLS.Server.Config.Handler = http.HandlerFunc(
|
||||||
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "CONNECT" {
|
||||||
|
connect = true
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !connect {
|
||||||
|
t.Log("connect not received")
|
||||||
|
http.Error(w, "connect not received", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
origHandler.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
|
||||||
|
cstDialer.TLSClientConfig = &tls.Config{RootCAs: rootCAs(t, sTLS.Server)}
|
||||||
|
ws, _, err := cstDialer.Dial(s.URL, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dial: %v", err)
|
||||||
|
}
|
||||||
|
defer ws.Close()
|
||||||
|
sendRecv(t, ws)
|
||||||
|
}
|
||||||
|
|
||||||
func TestProxyAuthorizationDial(t *testing.T) {
|
func TestProxyAuthorizationDial(t *testing.T) {
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
Loading…
Reference in New Issue