MCPcopy
hub / github.com/coyove/goflyway / dialUpstreamAndBridge

Method dialUpstreamAndBridge

proxy/client.go:220–264  ·  view source on GitHub ↗
(downstreamConn net.Conn, host string, resp []byte, extra, dialStyle byte)

Source from the content-addressed store, hash-verified

218}
219
220func (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
266func (proxy *ProxyClient) dialUpstreamAndBridgeWS(downstreamConn net.Conn, host string, resp []byte, extra, dialStyle byte) net.Conn {
267 upstreamConn, err := proxy.dialUpstream(dialStyle)

Callers 2

handleUDPtoTCPMethod · 0.95
DialUpstreamMethod · 0.95

Calls 12

dialUpstreamMethod · 0.95
WritesMethod · 0.95
encryptHostMethod · 0.95
genHostMethod · 0.95
OptionsTypeAlias · 0.85
readUntilFunction · 0.85
newRequestMethod · 0.80
SetMethod · 0.80
GetMethod · 0.80
CloseMethod · 0.45
WriteMethod · 0.45
BridgeMethod · 0.45

Tested by

no test coverage detected