From 86b2a17868c81326567ccf3b0f7bae0616775792 Mon Sep 17 00:00:00 2001 From: lzf Date: Fri, 11 Jul 2025 17:08:16 +0800 Subject: [PATCH] update --- myhttp/httpc/httpclient.go | 6 ++++-- myhttp/httpc/option.go | 15 +++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/myhttp/httpc/httpclient.go b/myhttp/httpc/httpclient.go index 5893533..0b5c1ea 100644 --- a/myhttp/httpc/httpclient.go +++ b/myhttp/httpc/httpclient.go @@ -232,8 +232,10 @@ func (r *Request) Do(method, rawUrl string) (*Response, error) { return nil, err } - if res.StatusCode != http.StatusOK { - return nil, fmt.Errorf("status code err: %d (%s)", res.StatusCode, body) + if r.httpClient.config.noCheckStatus == false { + if res.StatusCode != http.StatusOK { + return nil, fmt.Errorf("status code err: %d (%s)", res.StatusCode, body) + } } resp := &Response{ diff --git a/myhttp/httpc/option.go b/myhttp/httpc/option.go index 7dcdb48..61b8e8c 100644 --- a/myhttp/httpc/option.go +++ b/myhttp/httpc/option.go @@ -7,10 +7,11 @@ import ( type ( Config struct { - timeout time.Duration - client *http.Client - transport *http.Transport - redirectFn func(req *http.Request, via []*http.Request) error + timeout time.Duration + client *http.Client + transport *http.Transport + redirectFn func(req *http.Request, via []*http.Request) error + noCheckStatus bool } ConfigOpt func(c *Config) @@ -47,3 +48,9 @@ func WithNoRedirect() ConfigOpt { } } } + +func WithNoCheckStatus(v bool) ConfigOpt { + return func(c *Config) { + c.noCheckStatus = v + } +}