Skip to content

Commit 9344190

Browse files
committed
proxy: use internal http proxy
Looking into fd issues in production.
1 parent 2cca389 commit 9344190

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

proxy/main.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
"syscall"
1414
"time"
1515

16-
"github.com/elazarl/goproxy"
16+
// "github.com/elazarl/goproxy"
1717
"github.com/things-go/go-socks5"
1818

1919
"github.com/urnetwork/connect"
2020
"github.com/urnetwork/glog"
21+
"github.com/urnetwork/proxy"
2122
"github.com/urnetwork/server"
2223
"github.com/urnetwork/server/model"
2324
)
@@ -40,14 +41,16 @@ const ListenHttpsPort = 8082
4041

4142
func DefaultProxySettings() *ProxySettings {
4243
return &ProxySettings{
43-
TlsHandshakeTimeout: 30 * time.Second,
44-
ResponseHeaderTimeout: 30 * time.Second,
44+
ProxyReadTimeout: 60 * time.Second,
45+
ProxyWriteTimeout: 60 * time.Second,
46+
ProxyTlsHandshakeTimeout: 60 * time.Second,
4547
}
4648
}
4749

4850
type ProxySettings struct {
49-
TlsHandshakeTimeout time.Duration
50-
ResponseHeaderTimeout time.Duration
51+
ProxyReadTimeout time.Duration
52+
ProxyWriteTimeout time.Duration
53+
ProxyTlsHandshakeTimeout time.Duration
5154
}
5255

5356
func main() {
@@ -284,6 +287,8 @@ func (self *httpServer) run() {
284287
}
285288

286289
connectDialContext := func(r *http.Request, network string, addr string) (net.Conn, error) {
290+
fmt.Printf("CONNECT DIAL %s %s\n", network, addr)
291+
287292
return server.HandleError2(func() (net.Conn, error) {
288293
proxyId, err := authProxyId(r)
289294
if err != nil {
@@ -311,19 +316,22 @@ func (self *httpServer) run() {
311316

312317
}
313318

314-
httpProxy := goproxy.NewProxyHttpServer()
315-
httpProxy.Logger = self
316-
httpProxy.ConnectDialWithReq = connectDialContext
317-
httpProxy.AllowHTTP2 = true
318-
httpProxy.Tr = &http.Transport{
319-
TLSHandshakeTimeout: self.settings.TlsHandshakeTimeout,
320-
ResponseHeaderTimeout: self.settings.ResponseHeaderTimeout,
321-
IdleConnTimeout: 300 * time.Second,
322-
MaxIdleConns: 0,
323-
MaxIdleConnsPerHost: 4,
324-
MaxConnsPerHost: 0,
325-
ForceAttemptHTTP2: true,
326-
}
319+
httpProxy := proxy.NewHttpProxy()
320+
// httpProxy.Logger = self
321+
httpProxy.ConnectDialWithRequest = connectDialContext
322+
httpProxy.ProxyReadTimeout = self.settings.ProxyReadTimeout
323+
httpProxy.ProxyWriteTimeout = self.settings.ProxyWriteTimeout
324+
httpProxy.ProxyTlsHandshakeTimeout = self.settings.ProxyTlsHandshakeTimeout
325+
// httpProxy.AllowHTTP2 = true
326+
// httpProxy.Tr = &http.Transport{
327+
// TLSHandshakeTimeout: self.settings.TlsHandshakeTimeout,
328+
// ResponseHeaderTimeout: self.settings.ResponseHeaderTimeout,
329+
// IdleConnTimeout: 300 * time.Second,
330+
// MaxIdleConns: 0,
331+
// MaxIdleConnsPerHost: 4,
332+
// MaxConnsPerHost: 0,
333+
// ForceAttemptHTTP2: true,
334+
// }
327335

328336
// listen http
329337
go server.HandleError(func() {

0 commit comments

Comments
 (0)