Skip to content

Commit

Permalink
♻️ refactor: updated charge #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Nov 15, 2023
1 parent 53c2393 commit 288101d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions charge/charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,21 @@ func IsMobileRequest(req *http.Request) bool {
func IsStreamingRequest(req *http.Request) bool {
return strings.Contains(req.Header.Get("Accept"), "text/event-stream")
}

// IsPostForms check if the request is post form-data
func IsPostForms(req *http.Request) bool {
value := req.Header.Get("Content-Type")
return strings.HasPrefix(value, "application/x-www-form-urlencoded") ||
strings.HasPrefix(value, "multipart/form-data")
}

// GetPostForms get all post-form values as map
func GetPostForms(req *http.Request) map[string]string {
formValues := make(map[string]string)
for key, values := range req.PostForm {
if len(values) > 0 {
formValues[key] = values[0]
}
}
return formValues
}

0 comments on commit 288101d

Please sign in to comment.