change call option to ITask and delete old code
This commit is contained in:
parent
f7279cb755
commit
4710732833
|
@ -19,7 +19,7 @@ func init() {
|
|||
//"--"
|
||||
{"--header", 10, parseHeader, nil},
|
||||
{"--insecure", 15, parseInsecure, nil},
|
||||
{"--call", 10, parseCallBack, &extract{re: "--call +(.+)", execute: extractData}},
|
||||
{"--task", 10, parseITask, &extract{re: "--task +(.+)", execute: extractData}},
|
||||
{"--user-agent", 15, parseUserAgent, &extract{re: "--user-agent +(.+)", execute: extractData}},
|
||||
{"--user", 15, parseUser, &extract{re: "--user +(.+)", execute: extractData}},
|
||||
{"--connect-timeout", 15, parseTimeout, &extract{re: "--connect-timeout +(.+)", execute: extractData}},
|
||||
|
|
|
@ -27,11 +27,11 @@ type CURL struct {
|
|||
Timeout int // second
|
||||
Insecure bool
|
||||
|
||||
CallBack string
|
||||
ITask string
|
||||
}
|
||||
|
||||
// NewCURL new 一个 curl 出来
|
||||
func NewCURL() *CURL {
|
||||
// New new 一个 curl 出来
|
||||
func New() *CURL {
|
||||
|
||||
u := &CURL{}
|
||||
u.Insecure = false
|
||||
|
@ -110,7 +110,7 @@ func ParseRawCURL(scurl string) (cURL *CURL, err error) {
|
|||
}()
|
||||
|
||||
executor := newPQueueExecute()
|
||||
curl := NewCURL()
|
||||
curl := New()
|
||||
|
||||
if scurl[0] == '"' && scurl[len(scurl)-1] == '"' {
|
||||
scurl = strings.Trim(scurl, `"`)
|
||||
|
@ -162,87 +162,13 @@ func judgeOptions(u *CURL, soption string) *parseFunction {
|
|||
return nil
|
||||
}
|
||||
|
||||
func judgeAndParseOptions(u *CURL, soption string) *parseFunction {
|
||||
switch prefix := soption[0:2]; prefix {
|
||||
case "-H":
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseHeader, Priority: 10}
|
||||
case "-X":
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseOptX, Priority: 10}
|
||||
case "-A": // User-Agent 先后顺序的问题
|
||||
data := extractData("^-A +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseUserAgent, Priority: 15}
|
||||
case "-I":
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseOptI, Priority: 15}
|
||||
case "--":
|
||||
return parseLongOption(u, soption)
|
||||
case "-d":
|
||||
data := extractData("^-d +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyASCII, Priority: 10}
|
||||
case "-u":
|
||||
data := extractData("^-u +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseUser, Priority: 15}
|
||||
case "-k": // -k, --insecure Allow insecure server connections when using SSL
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseInsecure, Priority: 15}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseLongOption(u *CURL, soption string) *parseFunction {
|
||||
// -d, --data <data> HTTP POST data
|
||||
// --data-ascii <data> HTTP POST ASCII data
|
||||
// --data-binary <data> HTTP POST binary data
|
||||
// --data-raw <data> HTTP POST data, '@' allowed
|
||||
// --data-urlencode <data> HTTP POST data url encoded
|
||||
|
||||
switch {
|
||||
case regexp.MustCompile("^--data |^--data-urlencode|^--data-binary|^--data-ascii|^--data-raw").MatchString(soption):
|
||||
|
||||
datas := regexp.MustCompile("^--data-(binary) +(.+)|^--data-(ascii) +(.+)|^--data-(raw) +(.+)|^--data-(urlencode) +(.+)|^--(data) +(.+)").FindStringSubmatch(soption)
|
||||
dtype := datas[1]
|
||||
data := strings.Trim(datas[2], "'")
|
||||
|
||||
switch dtype {
|
||||
case "binary":
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyBinary, Priority: 10}
|
||||
case "ascii":
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyASCII, Priority: 10}
|
||||
case "raw":
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyRaw, Priority: 10}
|
||||
case "urlencode":
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyURLEncode, Priority: 10}
|
||||
case "data":
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseBodyASCII, Priority: 10}
|
||||
}
|
||||
|
||||
case regexp.MustCompile("^--header").MatchString(soption):
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseHeader, Priority: 10}
|
||||
case regexp.MustCompile("^--call").MatchString(soption):
|
||||
data := extractData("^--call +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseCallBack, Priority: 10}
|
||||
case regexp.MustCompile("^--user-agent").MatchString(soption):
|
||||
data := extractData("^--user-agent +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseUserAgent, Priority: 15}
|
||||
case regexp.MustCompile("^--user").MatchString(soption):
|
||||
data := extractData("^--user +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseUser, Priority: 15}
|
||||
case regexp.MustCompile("^--insecure").MatchString(soption):
|
||||
return &parseFunction{ParamCURL: u, ParamData: soption, ExecuteFunction: parseInsecure, Priority: 15}
|
||||
case regexp.MustCompile("^--connect-timeout").MatchString(soption):
|
||||
data := extractData("^--connect-timeout +(.+)", soption)
|
||||
return &parseFunction{ParamCURL: u, ParamData: data, ExecuteFunction: parseTimeout, Priority: 15}
|
||||
}
|
||||
|
||||
log.Println("can't parseOption", soption)
|
||||
return nil
|
||||
}
|
||||
|
||||
func extractData(re, soption string) string {
|
||||
datas := regexp.MustCompile(re).FindStringSubmatch(soption)
|
||||
return strings.Trim(datas[1], "'")
|
||||
}
|
||||
|
||||
func parseCallBack(u *CURL, value string) {
|
||||
u.CallBack = value
|
||||
func parseITask(u *CURL, value string) {
|
||||
u.ITask = value
|
||||
}
|
||||
|
||||
func parseTimeout(u *CURL, value string) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user