mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-23 16:41:30 +00:00
fix mitm for http1 proxy connections
Add back Hijacking support for http1.1 CONNECT requests.
This commit is contained in:
parent
fd53c9cb8c
commit
f9a6377450
|
@ -3,6 +3,7 @@ package proxy
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,14 +98,23 @@ func (p *Proxy) handleConnect(w http.ResponseWriter, r *http.Request) error {
|
||||||
return fmt.Errorf("CONNECT received but mitm is not enabled")
|
return fmt.Errorf("CONNECT received but mitm is not enabled")
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fw := w.(FlushWriter)
|
var conn net.Conn
|
||||||
fw.Flush()
|
if h, ok := w.(http.Hijacker); ok {
|
||||||
conn := newMitmConn(fw, r.Body, r.RemoteAddr)
|
conn, _, _ = h.Hijack()
|
||||||
|
} else {
|
||||||
|
fw := w.(FlushWriter)
|
||||||
|
fw.Flush()
|
||||||
|
mconn := newMitmConn(fw, r.Body, r.RemoteAddr)
|
||||||
|
conn = mconn
|
||||||
|
defer func() {
|
||||||
|
<-mconn.closed
|
||||||
|
}()
|
||||||
|
}
|
||||||
sconn, err := p.ml.Serve(conn, r.Host)
|
sconn, err := p.ml.Serve(conn, r.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sconn.Close() // TODO: reuse this connection for https requests
|
sconn.Close() // TODO: reuse this connection for https requests
|
||||||
<-conn.closed
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue