add origin request/response http method

master
兔子 2 years ago
parent 033272f38a
commit 0805549006

@ -32,6 +32,7 @@ type RequestFile struct {
type Request struct { type Request struct {
Url string Url string
RespURL string
Method string Method string
RecvData []byte RecvData []byte
RecvContentLength int64 RecvContentLength int64
@ -42,6 +43,8 @@ type Request struct {
Location *url.URL Location *url.URL
CircleBuffer *stario.StarBuffer CircleBuffer *stario.StarBuffer
respReader io.ReadCloser respReader io.ReadCloser
respOrigin *http.Response
reqOrigin *http.Request
RequestOpts RequestOpts
} }
@ -306,10 +309,15 @@ func Curl(curl Request) (resps Request, err error) {
curl.CircleBuffer = fpdst curl.CircleBuffer = fpdst
curl.ReqHeader.Set("Content-Type", "multipart/form-data;boundary="+boundary) curl.ReqHeader.Set("Content-Type", "multipart/form-data;boundary="+boundary)
} }
resp, err := netcurl(curl) req, resp, err := netcurl(curl)
if err != nil { if err != nil {
return Request{}, err return Request{}, err
} }
if resp.Request != nil && resp.Request.URL != nil {
curl.RespURL = resp.Request.URL.String()
}
curl.reqOrigin = req
curl.respOrigin = resp
curl.Location, _ = resp.Location() curl.Location, _ = resp.Location()
curl.RespHttpCode = resp.StatusCode curl.RespHttpCode = resp.StatusCode
curl.RespHeader = resp.Header curl.RespHeader = resp.Header
@ -367,11 +375,11 @@ func (curl *Request) RespBodyReader() io.ReadCloser {
return curl.respReader return curl.respReader
} }
func netcurl(curl Request) (*http.Response, error) { func netcurl(curl Request) (*http.Request, *http.Response, error) {
var req *http.Request var req *http.Request
var err error var err error
if curl.Method == "" { if curl.Method == "" {
return nil, errors.New("Error Method Not Entered") return nil, nil, errors.New("Error Method Not Entered")
} }
if curl.PostBuffer != nil { if curl.PostBuffer != nil {
req, err = http.NewRequest(curl.Method, curl.Url, curl.PostBuffer) req, err = http.NewRequest(curl.Method, curl.Url, curl.PostBuffer)
@ -388,7 +396,7 @@ func netcurl(curl Request) (*http.Response, error) {
req.URL.RawQuery = sid.Encode() req.URL.RawQuery = sid.Encode()
} }
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
req.Header = curl.ReqHeader req.Header = curl.ReqHeader
if len(curl.ReqCookies) != 0 { if len(curl.ReqCookies) != 0 {
@ -399,7 +407,7 @@ func netcurl(curl Request) (*http.Response, error) {
if curl.Proxy != "" { if curl.Proxy != "" {
purl, err := url.Parse(curl.Proxy) purl, err := url.Parse(curl.Proxy)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
curl.CustomTransport.Proxy = http.ProxyURL(purl) curl.CustomTransport.Proxy = http.ProxyURL(purl)
} }
@ -412,7 +420,8 @@ func netcurl(curl Request) (*http.Response, error) {
} }
} }
resp, err := client.Do(req) resp, err := client.Do(req)
return resp, err
return req, resp, err
} }
func UrlEncodeRaw(str string) string { func UrlEncodeRaw(str string) string {
@ -443,3 +452,11 @@ func BuildPostForm(queryMap map[string]string) []byte {
} }
return []byte(query.Encode()) return []byte(query.Encode())
} }
func (r Request) Resopnse() *http.Response {
return r.respOrigin
}
func (r Request) Request() *http.Request {
return r.reqOrigin
}

Loading…
Cancel
Save