From b46a0977df4a59c829aa38768b157afc644ba595 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:10:23 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=A6=84=20refactor:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete unnecessary return --- internal/altsvcutil/altsvcutil.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/altsvcutil/altsvcutil.go b/internal/altsvcutil/altsvcutil.go index 8aa160a0..84978d7e 100644 --- a/internal/altsvcutil/altsvcutil.go +++ b/internal/altsvcutil/altsvcutil.go @@ -79,7 +79,6 @@ func (p *altAvcParser) Parse() (as []*altsvc.AltSvc, err error) { } } } - return } func (p *altAvcParser) parseKv() (key, value string, haveNextField bool, err error) { From 9454280a852c5875f13609e77ebc6ed4d68cde66 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:27:42 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=A6=84=20refactor:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete redundant judgment --- middleware.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/middleware.go b/middleware.go index 59cd46f5..22d5504d 100644 --- a/middleware.go +++ b/middleware.go @@ -490,9 +490,9 @@ func parseRequestHeader(c *Client, r *Request) error { } func parseRequestCookie(c *Client, r *Request) error { - if len(c.Cookies) == 0 || r.RetryAttempt > 0 { - return nil + if len(c.Cookies) > 0 || r.RetryAttempt <= 0 { + r.Cookies = append(r.Cookies, c.Cookies...) } - r.Cookies = append(r.Cookies, c.Cookies...) + return nil } From 373b0b233d06b834c4834e85d1a107ec7535477c Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:29:36 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=A6=84=20refactor:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete redundant judgment --- client_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client_test.go b/client_test.go index ccf62f57..b87745cb 100644 --- a/client_test.go +++ b/client_test.go @@ -242,10 +242,7 @@ func TestAutoDecode(t *testing.T) { assertSuccess(t, resp, err) tests.AssertEqual(t, "我是roc", resp.String()) resp, err = c.SetAutoDecodeContentTypeFunc(func(contentType string) bool { - if strings.Contains(contentType, "text") { - return true - } - return false + return strings.Contains(contentType, "text") }).R().Get("/gbk") assertSuccess(t, resp, err) tests.AssertEqual(t, "我是roc", resp.String()) From 545f631981f33bbe8172f8d0f401360f7a14faf2 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:30:52 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=A6=84=20refactor:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete unnecessary return --- client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client.go b/client.go index 2631e6ce..dc7016d1 100644 --- a/client.go +++ b/client.go @@ -278,7 +278,6 @@ func (c *Client) appendRootCertData(data []byte) { config.RootCAs = x509.NewCertPool() } config.RootCAs.AppendCertsFromPEM(data) - return } // SetRootCertFromString set root certificates from string. From 4b43a2beb5c479d348efb077463ee0a411c538f7 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:44:46 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=A6=84=20refactor:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete unnecessary return --- middleware.go | 1 - 1 file changed, 1 deletion(-) diff --git a/middleware.go b/middleware.go index 22d5504d..c310cd3d 100644 --- a/middleware.go +++ b/middleware.go @@ -256,7 +256,6 @@ func unmarshalBody(c *Client, r *Response, v interface{}) (err error) { } return c.jsonUnmarshal(body, v) } - return } func defaultResultStateChecker(resp *Response) ResultState { From 004636e1ffa5d28021a57bf60bb958635b2fcdaa Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:47:46 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=8E=88=20perf:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace map[string]bool with map[string]struct{} to reduce memory footprint --- redirect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redirect.go b/redirect.go index 364a55eb..ed395845 100644 --- a/redirect.go +++ b/redirect.go @@ -55,9 +55,9 @@ func SameHostRedirectPolicy() RedirectPolicy { // AllowedHostRedirectPolicy allows redirect only if the redirected host // match one of the host that specified. func AllowedHostRedirectPolicy(hosts ...string) RedirectPolicy { - m := make(map[string]bool) + m := make(map[string]struct{}) for _, h := range hosts { - m[strings.ToLower(getHostname(h))] = true + m[strings.ToLower(getHostname(h))] = struct{}{} } return func(req *http.Request, via []*http.Request) error { From abca3e38b6aef91db1cd0b891c70cf91c80cb2fb Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 5 Sep 2024 16:49:09 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=8E=88=20perf:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace map[string]bool with map[string]struct{} to reduce memory footprint --- redirect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redirect.go b/redirect.go index ed395845..f1cc4331 100644 --- a/redirect.go +++ b/redirect.go @@ -72,9 +72,9 @@ func AllowedHostRedirectPolicy(hosts ...string) RedirectPolicy { // AllowedDomainRedirectPolicy allows redirect only if the redirected domain // match one of the domain that specified. func AllowedDomainRedirectPolicy(hosts ...string) RedirectPolicy { - domains := make(map[string]bool) + domains := make(map[string]struct{}) for _, h := range hosts { - domains[strings.ToLower(getDomain(h))] = true + domains[strings.ToLower(getDomain(h))] = struct{}{} } return func(req *http.Request, via []*http.Request) error {