From dea7bc45ee4cca51eaabebe0ab0ecc96dff229d4 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:46:11 +0800 Subject: [PATCH] fix: try to fix EOF error Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- internal/requester/requester.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/requester/requester.go b/internal/requester/requester.go index af8569b65..790098b44 100644 --- a/internal/requester/requester.go +++ b/internal/requester/requester.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "net/url" + "time" emperror "emperror.dev/errors" ) @@ -64,6 +65,14 @@ func (requester *Requester) GetURL(path string, query ...string) url.URL { return url } +var httpClient = &http.Client{ + Transport: &http.Transport{ + MaxIdleConns: 10, + IdleConnTimeout: 30 * time.Second, + DisableCompression: true, + }, +} + func (requester *Requester) Request(method string, url url.URL, body []byte, header http.Header) (resp *http.Response, respBody []byte, err error) { if url.Scheme == "" { url.Scheme = requester.GetSchema() @@ -89,11 +98,7 @@ func (requester *Requester) Request(method string, url url.URL, body []byte, hea if req.Header.Get("Accept") == "" { req.Header.Set("Accept", "application/json") } - req.Close = true - tr := http.DefaultTransport.(*http.Transport).Clone() - tr.TLSClientConfig.InsecureSkipVerify = true - httpClient := http.Client{Transport: tr} resp, err = httpClient.Do(req) if err != nil { return nil, nil, emperror.Wrap(err, "failed to request API")