Skip to content

Commit

Permalink
Merge pull request #382 from XiaoK29/dev
Browse files Browse the repository at this point in the history
Optimize coding
  • Loading branch information
imroc authored Sep 5, 2024
2 parents 7cb96a1 + abca3e3 commit 961617a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion internal/altsvcutil/altsvcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 961617a

Please sign in to comment.