Compare commits

...

3 Commits

Author SHA1 Message Date
wenzuochao 268f040e48 modify checkMaxLength 2020-03-20 13:05:33 +08:00
wenzuochao b56effc83d modify host 2020-03-12 11:17:26 +08:00
wenzuochao f4dd763f32 modify dorequest 2020-03-11 19:46:00 +08:00
2 changed files with 26 additions and 5 deletions
+16 -3
View File
@@ -246,8 +246,14 @@ func DoRequest(request *Request, requestRuntime map[string]interface{}) (respons
request.Port = 443
}
requestURL := ""
request.Domain = request.Headers["host"]
requestURL := fmt.Sprintf("%s://%s:%d%s", request.Protocol, request.Domain, request.Port, request.Pathname)
matched, _ := regexp.MatchString(":", request.Domain)
if matched {
requestURL = fmt.Sprintf("%s://%s%s", request.Protocol, request.Domain, request.Pathname)
} else {
requestURL = fmt.Sprintf("%s://%s:%d%s", request.Protocol, request.Domain, request.Port, request.Pathname)
}
queryParams := request.Query
// sort QueryParams by key
q := url.Values{}
@@ -285,8 +291,11 @@ func DoRequest(request *Request, requestRuntime map[string]interface{}) (respons
for key, value := range request.Headers {
if value == "" || key == "content-length" {
continue
} else if key == "host" {
httpRequest.Header["Host"] = []string{value}
} else {
httpRequest.Header[key] = []string{value}
}
httpRequest.Header[key] = []string{value}
debugLog("> %s: %s", key, value)
}
contentlength, _ := strconv.Atoi(request.Headers["content-length"])
@@ -839,7 +848,11 @@ func checkMaxLength(valueField reflect.Value, tag string) error {
if err != nil {
return err
}
if maxLength < valueField.Len() {
length := valueField.Len()
if valueField.Kind().String() == "string" {
length = len([]byte(valueField.String()))
}
if maxLength < length {
errMsg := fmt.Sprintf("Length of %s is more than %d", valueField.String(), maxLength)
return errors.New(errMsg)
}
+10 -2
View File
@@ -18,7 +18,8 @@ import (
)
type test struct {
Key string `json:"key"`
Key string `json:"key"`
Body []byte `json:"body"`
}
type PrettifyTest struct {
@@ -99,12 +100,14 @@ func TestResponse(t *testing.T) {
func TestConvert(t *testing.T) {
in := map[string]interface{}{
"key": "value",
"key": "value",
"body": []byte("test"),
}
out := new(test)
err := Convert(in, &out)
utils.AssertNil(t, err)
utils.AssertEqual(t, "value", out.Key)
utils.AssertEqual(t, "test", string(out.Body))
}
func TestConvertType(t *testing.T) {
@@ -354,6 +357,11 @@ func Test_DoRequest(t *testing.T) {
utils.AssertNil(t, resp)
utils.AssertEqual(t, `Internal error`, err.Error())
request.Headers["host"] = "tea-cn-hangzhou.aliyuncs.com:80"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, resp)
utils.AssertEqual(t, `Internal error`, err.Error())
runtimeObj["socks5Proxy"] = "# #%gfdf"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, resp)