Skip to content

Commit

Permalink
调整:GET请求,忽略Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Oct 30, 2023
1 parent 3d3a0f8 commit 4fe15a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions context/httpContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ func (httpContext *HttpContext) ParseParams() []reflect.Value {
return []reflect.Value{}
}

if httpContext.Method == "GET" {
return httpContext.Route.FormToParams(httpContext.Request.Query)
}

// application/json
switch httpContext.ContentType {
case "application/json":
return httpContext.Route.JsonToParams(httpContext.Request)
case "": // GET
return httpContext.Route.FormToParams(httpContext.Request.Query)
default: //case "application/x-www-form-urlencoded", "multipart/form-data":
return httpContext.Route.FormToParams(httpContext.Request.Query) // Query比Form有更齐全的值,所以不用Form
}
Expand Down
4 changes: 2 additions & 2 deletions context/httpRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *HttpRequest) jsonToMap() map[string]any {
return mapVal
}

// 解析来自form的值
// ParseForm 解析来自form的值
func (r *HttpRequest) ParseForm() {
for k, v := range r.R.Form {
key := strings.ToLower(k)
Expand All @@ -55,7 +55,7 @@ func (r *HttpRequest) ParseForm() {
}
}

// 解析来自url的值
// ParseQuery 解析来自url的值
func (r *HttpRequest) ParseQuery() {
for k, v := range r.R.URL.Query() {
key := strings.ToLower(k)
Expand Down

0 comments on commit 4fe15a6

Please sign in to comment.