mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
Make sure that closing one direction closes the other, too.
This commit is contained in:
parent
d710683181
commit
da52840a27
4 changed files with 22 additions and 56 deletions
24
http.go
24
http.go
|
@ -10,8 +10,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
||||
const proxyAuthHeaderKey = "Proxy-Authorization"
|
||||
|
@ -131,17 +129,19 @@ func (s *HTTPServer) serve(conn net.Conn) {
|
|||
log.Println("dial proxy failed: peer nil")
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg := conc.NewWaitGroup()
|
||||
wg.Go(func() {
|
||||
_, err = io.Copy(conn, peer)
|
||||
_ = conn.Close()
|
||||
})
|
||||
wg.Go(func() {
|
||||
_, err = io.Copy(peer, conn)
|
||||
_ = peer.Close()
|
||||
})
|
||||
wg.Wait()
|
||||
defer conn.Close()
|
||||
defer peer.Close()
|
||||
|
||||
io.Copy(conn, peer)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer conn.Close()
|
||||
defer peer.Close()
|
||||
|
||||
io.Copy(peer, conn)
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue