Browse Source

include package

fancl 1 year ago
parent
commit
ffac331e3d
2 changed files with 44 additions and 1 deletions
  1. 2 0
      instance.go
  2. 42 1
      pkg/request/client.go

+ 2 - 0
instance.go

@@ -4,11 +4,13 @@ import (
 	"git.nspix.com/golang/kos/entry/cli"
 	"git.nspix.com/golang/kos/entry/cli"
 	"git.nspix.com/golang/kos/entry/http"
 	"git.nspix.com/golang/kos/entry/http"
 	_ "git.nspix.com/golang/kos/pkg/request"
 	_ "git.nspix.com/golang/kos/pkg/request"
+	_ "git.nspix.com/golang/kos/util/arrays"
 	_ "git.nspix.com/golang/kos/util/bs"
 	_ "git.nspix.com/golang/kos/util/bs"
 	_ "git.nspix.com/golang/kos/util/fetch"
 	_ "git.nspix.com/golang/kos/util/fetch"
 	_ "git.nspix.com/golang/kos/util/humanize"
 	_ "git.nspix.com/golang/kos/util/humanize"
 	_ "git.nspix.com/golang/kos/util/random"
 	_ "git.nspix.com/golang/kos/util/random"
 	_ "git.nspix.com/golang/kos/util/reflection"
 	_ "git.nspix.com/golang/kos/util/reflection"
+	_ "git.nspix.com/golang/kos/util/sys"
 	"sync"
 	"sync"
 )
 )
 
 

+ 42 - 1
pkg/request/client.go

@@ -1,10 +1,13 @@
 package request
 package request
 
 
 import (
 import (
+	"crypto/tls"
 	"io"
 	"io"
+	"net"
 	"net/http"
 	"net/http"
 	"net/http/cookiejar"
 	"net/http/cookiejar"
 	"strings"
 	"strings"
+	"time"
 )
 )
 
 
 type (
 type (
@@ -21,6 +24,44 @@ type (
 	}
 	}
 )
 )
 
 
+var (
+	DefaultClient = &http.Client{
+		Transport: &http.Transport{
+			Proxy:                 http.ProxyFromEnvironment,
+			ForceAttemptHTTP2:     true,
+			MaxIdleConns:          64,
+			MaxIdleConnsPerHost:   8,
+			IdleConnTimeout:       90 * time.Second,
+			TLSHandshakeTimeout:   10 * time.Second,
+			ExpectContinueTimeout: 1 * time.Second,
+			TLSClientConfig: &tls.Config{
+				InsecureSkipVerify: true,
+			},
+		},
+		Timeout: time.Second * 30,
+	}
+
+	UnsafeClient = &http.Client{
+		Transport: &http.Transport{
+			Proxy:             http.ProxyFromEnvironment,
+			ForceAttemptHTTP2: true,
+			DialContext: (&net.Dialer{
+				Timeout:   30 * time.Second,
+				KeepAlive: 30 * time.Second,
+			}).DialContext,
+			MaxIdleConns:          64,
+			MaxIdleConnsPerHost:   8,
+			IdleConnTimeout:       90 * time.Second,
+			TLSHandshakeTimeout:   10 * time.Second,
+			ExpectContinueTimeout: 1 * time.Second,
+			TLSClientConfig: &tls.Config{
+				InsecureSkipVerify: true,
+			},
+		},
+		Timeout: time.Second * 30,
+	}
+)
+
 func (client *Client) stashUri(urlPath string) string {
 func (client *Client) stashUri(urlPath string) string {
 	var (
 	var (
 		pos int
 		pos int
@@ -139,7 +180,7 @@ func (client *Client) execute(r *Request) (res *http.Response, err error) {
 
 
 func New() *Client {
 func New() *Client {
 	client := &Client{
 	client := &Client{
-		client:              http.DefaultClient,
+		client:              DefaultClient,
 		interceptorRequest:  make([]BeforeRequest, 0, 10),
 		interceptorRequest:  make([]BeforeRequest, 0, 10),
 		interceptorResponse: make([]AfterRequest, 0, 10),
 		interceptorResponse: make([]AfterRequest, 0, 10),
 	}
 	}