(downstreamConn net.Conn, host string, resp []byte, extra, dialStyle byte)
| 218 | } |
| 219 | |
| 220 | func (proxy *ProxyClient) dialUpstreamAndBridge(downstreamConn net.Conn, host string, resp []byte, extra, dialStyle byte) net.Conn { |
| 221 | upstreamConn, err := proxy.dialUpstream(0) |
| 222 | if err != nil { |
| 223 | proxy.Logger.E("Dial", "Error", err) |
| 224 | downstreamConn.Close() |
| 225 | return nil |
| 226 | } |
| 227 | |
| 228 | r := proxy.Cipher.newRequest() |
| 229 | r.Opt = Options(doConnect | extra) |
| 230 | r.Auth = proxy.UserAuth |
| 231 | if proxy.Partial { |
| 232 | r.Opt.Set(doPartial) |
| 233 | } |
| 234 | |
| 235 | var pl buffer |
| 236 | pl.Writes("GET /", proxy.encryptHost(host, r), " HTTP/1.1\r\nHost: ", proxy.genHost(), "\r\n") |
| 237 | |
| 238 | for _, h := range dummyHeaders { |
| 239 | if v, ok := proxy.dummies.Get(h); ok && v.(string) != "" { |
| 240 | pl.Writes(h, ": ", v.(string), "\r\n") |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | upstreamConn.Write(pl.Writes("\r\n").Bytes()) |
| 245 | buf, err := readUntil(upstreamConn, "\r\n\r\n") |
| 246 | // the first 15 bytes MUST be "HTTP/1.1 200 OK" |
| 247 | if err != nil || len(buf) < 15 || !bytes.Equal(buf[:15], []byte("HTTP/1.1 200 OK")) { |
| 248 | if err != nil { |
| 249 | proxy.Logger.E("Client", "Invalid response", host, err) |
| 250 | } |
| 251 | |
| 252 | upstreamConn.Close() |
| 253 | downstreamConn.Close() |
| 254 | return nil |
| 255 | } |
| 256 | |
| 257 | if resp != nil { |
| 258 | downstreamConn.Write(resp) |
| 259 | } |
| 260 | |
| 261 | go proxy.Cipher.IO.Bridge(downstreamConn, upstreamConn, &r.iv, IOConfig{Partial: proxy.Partial}) |
| 262 | |
| 263 | return upstreamConn |
| 264 | } |
| 265 | |
| 266 | func (proxy *ProxyClient) dialUpstreamAndBridgeWS(downstreamConn net.Conn, host string, resp []byte, extra, dialStyle byte) net.Conn { |
| 267 | upstreamConn, err := proxy.dialUpstream(dialStyle) |
no test coverage detected