feat(RuCaptcha): add post form support
All checks were successful
release-tag / release (push) Successful in 1m58s

This commit is contained in:
sati.ac 2023-07-26 08:15:34 +03:00
parent 8f3d67c648
commit a9cf77ca52

@ -37,6 +37,27 @@ 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" {
var err error
switch strings.ToLower(r.Header.Get("Content-Type")) {
case "application/x-www-form-urlencoded":
err = r.ParseForm()
case "multipart/form-data":
err = r.ParseMultipartForm(0)
}
if err != nil {
// 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