mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-09-10 12:57:23 +00:00
Add http2 using the go-1.6 net/http built-in support. net/http's http2 doesn't support hijacking, so instead of hijacking the inital CONNECT tcp connection, tunnel proxied requests/responses over the reader and writer streams of the CONNECT request.
75 lines
1.2 KiB
Go
75 lines
1.2 KiB
Go
package proxy
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type mitmConn struct {
|
|
w FlushWriter
|
|
r io.Reader
|
|
remoteAddr addr
|
|
closed chan struct{}
|
|
}
|
|
|
|
type FlushWriter interface {
|
|
io.Writer
|
|
http.Flusher
|
|
}
|
|
|
|
func newMitmConn(w FlushWriter, r io.Reader, remoteAddr string) *mitmConn {
|
|
return &mitmConn{
|
|
w: w,
|
|
r: r,
|
|
remoteAddr: addr(remoteAddr),
|
|
closed: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func (c *mitmConn) Read(b []byte) (int, error) {
|
|
return c.r.Read(b)
|
|
}
|
|
|
|
func (c *mitmConn) Write(b []byte) (int, error) {
|
|
n, err := c.w.Write(b)
|
|
c.w.Flush()
|
|
return n, err
|
|
}
|
|
|
|
func (c *mitmConn) Close() error {
|
|
close(c.closed)
|
|
return nil
|
|
}
|
|
|
|
func (c *mitmConn) RemoteAddr() net.Addr {
|
|
return c.remoteAddr
|
|
}
|
|
|
|
func (c *mitmConn) LocalAddr() net.Addr {
|
|
panic("not implemented")
|
|
}
|
|
|
|
func (c *mitmConn) SetDeadline(t time.Time) error {
|
|
panic("not implemented")
|
|
}
|
|
|
|
func (c *mitmConn) SetReadDeadline(t time.Time) error {
|
|
panic("not implemented")
|
|
}
|
|
|
|
func (c *mitmConn) SetWriteDeadline(t time.Time) error {
|
|
panic("not implemented")
|
|
}
|
|
|
|
type addr string
|
|
|
|
func (a addr) String() string {
|
|
return string(a)
|
|
}
|
|
|
|
func (a addr) Network() string {
|
|
return "tcp"
|
|
}
|