internal/http_client.go

29 lines · 557 bytes

 1package internal
 2
 3import (
 4	"net/http"
 5	"net/http/cookiejar"
 6	"net/url"
 7	"time"
 8)
 9
10var sharedHTTPClient *http.Client
11
12func SetCookiesForAnimepahe(u *url.URL, cookies []*http.Cookie) {
13	if sharedHTTPClient != nil && sharedHTTPClient.Jar != nil {
14		sharedHTTPClient.Jar.SetCookies(u, cookies)
15	}
16}
17
18func init() {
19	jar, _ := cookiejar.New(nil)
20	sharedHTTPClient = &http.Client{
21		Transport: &http.Transport{
22			MaxIdleConns:        10,
23			MaxIdleConnsPerHost: 5,
24			IdleConnTimeout:     30 * time.Second,
25		},
26		Timeout: 15 * time.Second,
27		Jar:     jar,
28	}
29}