improve parameter handing for ghttp.Request
@@ -278,14 +278,16 @@ func (r *Request) parseForm() {
for name, values := range r.PostForm {
// Invalid parameter name.
// Only allow chars of: '\w', '[', ']', '-'.
- if !gregex.IsMatchString(`^[\w\-\[\]]+$`, name) {
- if len(r.PostForm) == 1 {
+ if !gregex.IsMatchString(`^[\w\-\[\]]+$`, name) && len(r.PostForm) == 1 {
// It might be JSON/XML content.
- r.bodyContent = gconv.UnsafeStrToBytes(name + strings.Join(values, " "))
- }
+ if s := name + strings.Join(values, " "); len(s) > 0 {
+ if s[0] == '{' && s[len(s)-1] == '}' || s[0] == '<' && s[len(s)-1] == '>' {
+ r.bodyContent = gconv.UnsafeStrToBytes(s)
params = ""
break
}
+ }
+ }
if len(values) == 1 {
if len(params) > 0 {
params += "&"
@@ -308,10 +310,12 @@ func (r *Request) parseForm() {
}
}
}
+ if params != "" {
if r.formMap, err = gstr.Parse(params); err != nil {
panic(err)
}
}
+ }
if r.formMap == nil {
r.parseBody()
if len(r.bodyMap) > 0 {
