try fix use too many port problem

addon-dailer
lqqyt2423 3 years ago
parent 88fe6dbe8d
commit 7faa3ce5ad

@ -12,7 +12,7 @@ import (
log "github.com/sirupsen/logrus"
)
const version = "0.1.3"
const version = "0.1.4"
type Config struct {
version bool

@ -3,7 +3,6 @@ package proxy
import (
"bytes"
"io"
"net"
"os"
"strings"
"sync"
@ -40,11 +39,11 @@ func LogErr(log *_log.Entry, err error) (loged bool) {
// 转发流量
// Read a => Write b
// Read b => Write a
func Transfer(log *_log.Entry, a, b io.ReadWriteCloser) {
func Transfer(log *_log.Entry, a, b io.ReadWriter) {
done := make(chan struct{})
defer close(done)
forward := func(dst io.WriteCloser, src io.Reader, ec chan<- error) {
forward := func(dst io.Writer, src io.Reader, ec chan<- error) {
_, err := io.Copy(dst, src)
if err != nil {
select {
@ -55,12 +54,6 @@ func Transfer(log *_log.Entry, a, b io.ReadWriteCloser) {
}
}
if dstc, ok := dst.(*net.TCPConn); ok {
err = dstc.CloseWrite()
} else {
err = dst.Close()
}
select {
case <-done:
return

@ -6,6 +6,7 @@ import (
"net"
"net/http"
"strings"
"time"
"github.com/lqqyt2423/go-mitmproxy/cert"
)
@ -85,6 +86,7 @@ func NewMiddle(proxy *Proxy) (Interceptor, error) {
server := &http.Server{
Handler: m,
IdleTimeout: 5 * time.Second,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)), // disable http2
TLSConfig: &tls.Config{
GetCertificate: func(chi *tls.ClientHelloInfo) (*tls.Certificate, error) {

@ -33,8 +33,9 @@ func NewProxy(opts *Options) (*Proxy, error) {
proxy := new(Proxy)
proxy.Server = &http.Server{
Addr: opts.Addr,
Handler: proxy,
Addr: opts.Addr,
Handler: proxy,
IdleTimeout: 5 * time.Second,
}
proxy.Client = &http.Client{
@ -278,6 +279,9 @@ func (proxy *Proxy) handleConnect(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(502)
return
}
// send RST other than FIN when finished, to avoid TIME_WAIT state
cconn.(*net.TCPConn).SetLinger(0)
defer cconn.Close()
_, err = io.WriteString(cconn, "HTTP/1.1 200 Connection Established\r\n\r\n")

Loading…
Cancel
Save