package requests import ( "net/http" "testing" "474420502.top/eson/gjson" ) func TestFromHTTPResponse(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, false) 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") } } func TestResponseDeflate(t *testing.T) { ses := NewSession() if wf := ses.Get("http://httpbin.org/get"); wf != nil { wf.AddHeader("accept-encoding", "deflate") resp, err := wf.Execute() if err != nil { t.Error(err) } else { if gjson.Get(resp.Content(), "headers.Accept-Encoding").String() != "deflate" { t.Error("Accept-Encoding != deflate ?") } } } }