lib/tunnel: make each conn have its own server

This commit is contained in:
Cadey Ratio 2017-01-23 09:11:19 -08:00
parent 48327a7669
commit f3c299acf9
1 changed files with 6 additions and 5 deletions

View File

@ -62,12 +62,9 @@ func (p *HTTPProxy) Proxy(remote net.Conn, msg *proto.ControlMessage) {
localAddr = p.LocalAddr
}
if p.hs == nil {
if p.rp == nil {
su, _ := url.Parse(fmt.Sprintf("http://%s", p.LocalAddr))
p.rp = httputil.NewSingleHostReverseProxy(su)
p.hs = &http.Server{
Handler: p.rp,
}
}
log.Debug("Dialing local server %q", localAddr)
@ -76,7 +73,11 @@ func (p *HTTPProxy) Proxy(remote net.Conn, msg *proto.ControlMessage) {
conn: remote,
}
err := p.hs.Serve(sl)
hs := &http.Server{
Handler: p.rp,
}
err := hs.Serve(sl)
if err != nil {
log.Error("Dialing local server %q failed: %s", localAddr, err)
p.sendError(remote)