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