Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ var disableRedirect = func(request *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}

var (
DEFAULT_TRANSPORT *http.Transport // 默认 Transport
defineTransport sync.Once
)

const (
DEFAULT_REDIRECT_LIMIT = 30 // 默认redirect最大次数
DEFAULT_TIMEOUT = 10 // 默认client响应时间
Expand All @@ -151,14 +156,20 @@ func NewSession() *Session {
}
cookies, _ := cookiejar.New(nil)
session.Cookies = cookies
session.transport = &http.Transport{
TLSClientConfig: &utls.Config{
InsecureSkipVerify: session.Verify,
OmitEmptyPsk: true,
},
DisableKeepAlives: false, // 这里问题很严重
}
session.request = &http.Request{}

defineTransport.Do(func() {
// Transports should be reused instead of created as needed.
// Transports are safe for concurrent use by multiple goroutines.
DEFAULT_TRANSPORT = &http.Transport{
TLSClientConfig: &utls.Config{
InsecureSkipVerify: session.Verify,
OmitEmptyPsk: true,
},
DisableKeepAlives: false,
}
})
session.transport = DEFAULT_TRANSPORT

session.client = &http.Client{
Transport: session.transport,
CheckRedirect: nil,
Expand Down