feat(RuCaptcha): add post form support

sati.ac 2023-07-26 08:15:03 +03:00
parent 8f3d67c648
commit 7dcc63c627
1 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,24 @@ type ruCaptchaResponse interface{ text() string }
func (a *ruCaptchaApi) wrap(handler func(url.Values) ruCaptchaResponse) func(http.ResponseWriter, *http.Request) { func (a *ruCaptchaApi) wrap(handler func(url.Values) ruCaptchaResponse) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query() query := r.URL.Query()
if r.Method != "GET" {
switch strings.ToLower(r.Header.Get("Content-Type")) {
case "application/x-www-form-urlencoded":
r.ParseForm()
case "multipart/form-data":
r.ParseMultipartForm(0)
}
// merge form with url params
for key, values := range r.Form {
if _, ok := query[key]; ok {
query[key] = append(query[key], values...)
} else {
query[key] = values
}
}
}
useJson := false useJson := false
if val := query.Get("json"); val != "" && val != "0" { if val := query.Get("json"); val != "" && val != "0" {
useJson = true useJson = true