]> 127.0.0.1 Git - part/.git/commitdiff
1 (#62) v0.28.20250530180625
authorqydysky <qydysky@foxmail.com>
Fri, 30 May 2025 18:06:15 +0000 (02:06 +0800)
committerGitHub <noreply@github.com>
Fri, 30 May 2025 18:06:15 +0000 (02:06 +0800)
reqf/Reqf.go
reqf/Reqf_test.go

index ec1bb470eff154c466eac210d65fca9c57b1c37f..1e0d50bc59e1dc50c9788548dc2b5596bdbcf85a 100644 (file)
@@ -125,15 +125,30 @@ func (t *Req) Reqf(val Rval) error {
 func (t *Req) ResStatusCode() (code int) {
        t.l.RLock()
        defer t.l.RUnlock()
+       if t.response == nil {
+               return 0
+       }
        return t.response.StatusCode
 }
 
 func (t *Req) ResHeader() http.Header {
        t.l.RLock()
        defer t.l.RUnlock()
+       if t.response == nil {
+               return nil
+       }
        return t.response.Header.Clone()
 }
 
+func (t *Req) ResCookies(f func(cs []*http.Cookie) error) error {
+       t.l.RLock()
+       defer t.l.RUnlock()
+       if t.response == nil {
+               return nil
+       }
+       return f(t.response.Cookies())
+}
+
 func (t *Req) Response(f func(r *http.Response) error) error {
        t.l.RLock()
        defer t.l.RUnlock()
index 35e3f41f1099a073a3b9c71956c63fce2d9ce3e2..4e63159c72456c011dff6ddfd634cfdeb79a33ab 100644 (file)
@@ -123,6 +123,16 @@ func init() {
        })
 }
 
+func Test_9(t *testing.T) {
+       reuse.Reqf(Rval{
+               Url:                   "http://" + addr + "1/nores",
+               ResponseHeaderTimeout: 500,
+       })
+       if reuse.ResStatusCode() != 0 {
+               t.Fatal()
+       }
+}
+
 func Test_7(t *testing.T) {
        e := reuse.Reqf(Rval{
                Url:                   "http://" + addr + "/nores",