Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag : no need sort raw query data #238

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions gorequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,30 @@ type superAgentRetryable struct {

// A SuperAgent is a object storing all request data for client.
type SuperAgent struct {
Url string
Method string
Header http.Header
TargetType string
ForceType string
Data map[string]interface{}
SliceData []interface{}
FormData url.Values
QueryData url.Values
FileData []File
BounceToRawString bool
RawString string
Client *http.Client
Transport *http.Transport
Cookies []*http.Cookie
Errors []error
BasicAuth struct{ Username, Password string }
Debug bool
CurlCommand bool
logger Logger
Retryable superAgentRetryable
DoNotClearSuperAgent bool
isClone bool
Url string
Method string
Header http.Header
TargetType string
ForceType string
Data map[string]interface{}
SliceData []interface{}
FormData url.Values
QueryData url.Values
IsNotSortRawQueryFlag bool // Added Henry Huang
FileData []File
BounceToRawString bool
RawString string
Client *http.Client
Transport *http.Transport
Cookies []*http.Cookie
Errors []error
BasicAuth struct{ Username, Password string }
Debug bool
CurlCommand bool
logger Logger
Retryable superAgentRetryable
DoNotClearSuperAgent bool
isClone bool
}

var DisableTransportSwap = false
Expand Down Expand Up @@ -828,6 +829,13 @@ func (s *SuperAgent) SendString(content string) *SuperAgent {
return s
}

// SetIsNotSortRawQueryFlag Added by Henry Huang
// set flag - raw query data if sorted with superagent's query data
func (s *SuperAgent) SetIsNotSortRawQueryFlag(flag bool) *SuperAgent {
s.IsNotSortRawQueryFlag = flag
return s
}

type File struct {
Filename string
Fieldname string
Expand Down Expand Up @@ -1373,14 +1381,24 @@ func (s *SuperAgent) MakeRequest() (*http.Request, error) {
req.Header.Set("Content-Type", contentType)
}

// Add all querystring from Query func
q := req.URL.Query()
// Update by Henry Huang
q := url.Values{}
if !s.IsNotSortRawQueryFlag {
// Add all querystring from Query func
q = req.URL.Query()
req.URL.RawQuery = ""
}

for k, v := range s.QueryData {
for _, vv := range v {
q.Add(k, vv)
}
}
req.URL.RawQuery = q.Encode()

if 0 != len(req.URL.RawQuery) && 0 != len(s.QueryData) {
req.URL.RawQuery += "&"
}
req.URL.RawQuery += q.Encode()

// Add basic auth
if s.BasicAuth != struct{ Username, Password string }{} {
Expand Down