diff --git a/response.go b/response.go index 22bd335..ac7428b 100644 --- a/response.go +++ b/response.go @@ -54,3 +54,8 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) { func (gresp *Response) Content() string { return gresp.readContent } + +// GetSrcResponse 获取原生golang http.Response +func (gresp *Response) GetSrcResponse() *http.Response { + return gresp.readResponse +} diff --git a/response_test.go b/response_test.go index db31d76..2b4511b 100644 --- a/response_test.go +++ b/response_test.go @@ -1,9 +1,34 @@ package requests import ( + "net/http" "testing" + + "474420502.top/eson/gjson" ) func TestTest(t *testing.T) { + var gresp *http.Response + var err error + gresp, err = http.DefaultClient.Get("http://httpbin.org/get") + if err != nil { + t.Error(err) + } + resp, err := FromHTTPResponse(gresp) + if err != nil { + t.Error(err) + } + + if gjson.Get(resp.Content(), "headers.Host").String() != "httpbin.org" { + t.Error("headers.Host != httpbin.org ?") + } + + if resp.GetSrcResponse().StatusCode != 200 { + t.Error("StatusCode != 200") + } + + if len(resp.GetSrcResponse().Header) == 0 { + t.Error("esp.GetSrcResponse().Header == nil") + } } diff --git a/session_test.go b/session_test.go index a3d61a6..d4baa1f 100644 --- a/session_test.go +++ b/session_test.go @@ -76,7 +76,7 @@ func TestSession_Post(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ses := NewSession() - got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params...).Execute() + got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params...).Execute() if err != nil { t.Errorf("Metchod error = %v", err) @@ -127,7 +127,7 @@ func TestSession_Setparams(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ses := NewSession() - got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params...).Execute() + got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params...).Execute() if (err != nil) != tt.wantErr { t.Errorf("Metchod error = %v, wantErr %v", err, tt.wantErr) return @@ -169,7 +169,7 @@ func TestSession_PostUploadFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ses := NewSession() - got, err := ses.Post("http://httpbin.org/post").AutoSetBody(tt.args.params, TypeFormData).Execute() + got, err := ses.Post("http://httpbin.org/post").SetBodyAuto(tt.args.params, TypeFormData).Execute() if err != nil { t.Errorf("Metchod error = %v", err) @@ -213,7 +213,7 @@ func TestSession_Put(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ses := NewSession() - got, err := ses.Put("http://httpbin.org/put").AutoSetBody(tt.args.params, TypeFormData).Execute() + got, err := ses.Put("http://httpbin.org/put").SetBodyAuto(tt.args.params, TypeFormData).Execute() if err != nil { t.Errorf("Metchod error = %v", err) @@ -257,7 +257,7 @@ func TestSession_Patch(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ses := NewSession() - got, err := ses.Patch("http://httpbin.org/patch").AutoSetBody(tt.args.params, TypeFormData).Execute() + got, err := ses.Patch("http://httpbin.org/patch").SetBodyAuto(tt.args.params, TypeFormData).Execute() if err != nil { t.Errorf("Metchod error = %v", err) diff --git a/workflow.go b/workflow.go index 4375a80..503bfe4 100644 --- a/workflow.go +++ b/workflow.go @@ -173,25 +173,25 @@ func (wf *Workflow) GetURLRawPath() string { } // encodePath path格式每个item都必须以/开头 -func encodePath(path []string) string { - rawpath := "" - for _, p := range path { - if p[0] != '/' { - p = "/" + p - } - rawpath += p - } - return rawpath -} +// func encodePath(path []string) string { +// rawpath := "" +// for _, p := range path { +// if p[0] != '/' { +// p = "/" + p +// } +// rawpath += p +// } +// return rawpath +// } -// SetURLPath 设置Path参数 -func (wf *Workflow) SetURLPath(path []string) *Workflow { - if path == nil { - return wf - } - wf.ParsedURL.Path = encodePath(path) - return wf -} +// // SetURLPath 设置Path参数 +// func (wf *Workflow) SetURLPath(path []string) *Workflow { +// if path == nil { +// return wf +// } +// wf.ParsedURL.Path = encodePath(path) +// return wf +// } // SetURLRawPath 设置Pa晚上参数 func (wf *Workflow) SetURLRawPath(path string) *Workflow { @@ -210,8 +210,8 @@ func (wf *Workflow) GetBody(body IBody) IBody { return wf.Body } -// AutoSetBody 参数设置 -func (wf *Workflow) AutoSetBody(params ...interface{}) *Workflow { +// SetBodyAuto 参数设置 +func (wf *Workflow) SetBodyAuto(params ...interface{}) *Workflow { if params != nil { plen := len(params)