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. (#159)
* Make sure that closing one direction closes the other, too. * Pacify linter.
This commit is contained in:
parent
47cd451c80
commit
7bb1be2d20
4 changed files with 23 additions and 57 deletions
26
http.go
26
http.go
|
@ -10,8 +10,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
||||
const proxyAuthHeaderKey = "Proxy-Authorization"
|
||||
|
@ -32,7 +30,7 @@ func (s *HTTPServer) authenticate(req *http.Request) (int, error) {
|
|||
|
||||
auth := req.Header.Get(proxyAuthHeaderKey)
|
||||
if auth == "" {
|
||||
return http.StatusProxyAuthRequired, fmt.Errorf(http.StatusText(http.StatusProxyAuthRequired))
|
||||
return http.StatusProxyAuthRequired, fmt.Errorf("%s", http.StatusText(http.StatusProxyAuthRequired))
|
||||
}
|
||||
|
||||
enc := strings.TrimPrefix(auth, "Basic ")
|
||||
|
@ -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