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. 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()) 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) { diff --git a/middleware.go b/middleware.go index 59cd46f5..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 { @@ -490,9 +489,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 } diff --git a/redirect.go b/redirect.go index 364a55eb..f1cc4331 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 { @@ -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 {