2016-03-26 17:52:06 +00:00
|
|
|
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 {
|
2017-06-09 13:06:02 +00:00
|
|
|
return nil
|
2016-03-26 17:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *mitmConn) SetReadDeadline(t time.Time) error {
|
2017-06-09 13:06:02 +00:00
|
|
|
return nil
|
2016-03-26 17:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *mitmConn) SetWriteDeadline(t time.Time) error {
|
2017-06-09 13:06:02 +00:00
|
|
|
return nil
|
2016-03-26 17:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type addr string
|
|
|
|
|
|
|
|
func (a addr) String() string {
|
|
|
|
return string(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a addr) Network() string {
|
|
|
|
return "tcp"
|
|
|
|
}
|