From 3b3698d084d17def17f7d1f4aa0e01a0dcab2928 Mon Sep 17 00:00:00 2001 From: "jared.lu" Date: Tue, 5 Nov 2024 20:13:55 +0800 Subject: [PATCH] =?UTF-8?q?httpx:=E5=A2=9E=E5=8A=A0error=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net/httpx/request.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/httpx/request.go b/net/httpx/request.go index e47e4d9..b4e361e 100644 --- a/net/httpx/request.go +++ b/net/httpx/request.go @@ -39,6 +39,9 @@ func NewRequest(ctx context.Context, method, url string) *Request { // JSONBody 使用 JSON body func (req *Request) JSONBody(val any) *Request { + if req.err != nil { + return req + } req.req.Body = io.NopCloser(iox.NewJSONReader(val)) req.req.Header.Set("Content-Type", "application/json") return req @@ -50,6 +53,9 @@ func (req *Request) Client(cli *http.Client) *Request { } func (req *Request) AddHeader(key string, value string) *Request { + if req.err != nil { + return req + } req.req.Header.Add(key, value) return req } @@ -57,6 +63,9 @@ func (req *Request) AddHeader(key string, value string) *Request { // AddParam 添加查询参数 // 这个方法性能不好,但是好用 func (req *Request) AddParam(key string, value string) *Request { + if req.err != nil { + return req + } q := req.req.URL.Query() q.Add(key, value) req.req.URL.RawQuery = q.Encode()