Proxying Connection method

Hey guys,

Has anyone had any luck proxying http.Requets over libp2p when using the request uses the CONNECTION method?

GET requests are quite simple as you just pass the http.Request object around over a stream
User makes request to proxy server -> proxy server creates stream with libp2p peer -> request sent over stream to libp2p peer-> peer executes the request and gets response from webserver -> peer passes response back to original requester over stream
see example here https://github.com/libp2p/go-libp2p-examples/blob/master/http-proxy/proxy.go

Most HTTPS requests use the CONNECT method which creates tunnels between the user and server and example below shows the creation of the tunnel in the net.DialTimout to the r.Host or target URL resulting in a net.conn object. Below any request with the method=connect passed onto handleTunneling

func handleTunneling(w http.ResponseWriter, r *http.Request) { dest_conn, err := net.DialTimeout("tcp", r.Host, 10*time.Second) if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return } w.WriteHeader(http.StatusOK) hijacker, ok := w.(http.Hijacker) if !ok { http.Error(w, "Hijacking not supported", http.StatusInternalServerError) return } client_conn, _, err := hijacker.Hijack() if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) } go transfer(dest_conn, client_conn) go transfer(client_conn, dest_conn) } func transfer(destination io.WriteCloser, source io.ReadCloser) { defer destination.Close() defer source.Close() io.Copy(destination, source) }

I think it is possible if the streams are all read/written to in the correct order but I cant for the life of me work it out.

Something like
go transfer(dest_conn, libp2pstream_proxy_client network.Stream)
and then on the proxy client
go transfer(libp2pstream_proxy_client network.Stream, dest_conn)
May work

Anyone got any ideas or guidance?