| 149 | } |
| 150 | |
| 151 | func TestProxyDial(t *testing.T) { |
| 152 | |
| 153 | s := newServer(t) |
| 154 | defer s.Close() |
| 155 | |
| 156 | surl, _ := url.Parse(s.Server.URL) |
| 157 | |
| 158 | cstDialer := cstDialer // make local copy for modification on next line. |
| 159 | cstDialer.Proxy = http.ProxyURL(surl) |
| 160 | |
| 161 | connect := false |
| 162 | origHandler := s.Server.Config.Handler |
| 163 | |
| 164 | // Capture the request Host header. |
| 165 | s.Server.Config.Handler = http.HandlerFunc( |
| 166 | func(w http.ResponseWriter, r *http.Request) { |
| 167 | if r.Method == http.MethodConnect { |
| 168 | connect = true |
| 169 | w.WriteHeader(http.StatusOK) |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | if !connect { |
| 174 | t.Log("connect not received") |
| 175 | http.Error(w, "connect not received", http.StatusMethodNotAllowed) |
| 176 | return |
| 177 | } |
| 178 | origHandler.ServeHTTP(w, r) |
| 179 | }) |
| 180 | |
| 181 | ws, _, err := cstDialer.Dial(s.URL, nil) |
| 182 | if err != nil { |
| 183 | t.Fatalf("Dial: %v", err) |
| 184 | } |
| 185 | defer ws.Close() |
| 186 | sendRecv(t, ws) |
| 187 | } |
| 188 | |
| 189 | func TestProxyAuthorizationDial(t *testing.T) { |
| 190 | s := newServer(t) |