Add support for multipart/form-data request parsing

This commit is contained in:
Tomaž Jerman
2021-12-21 09:11:51 +01:00
parent ff7f642681
commit 907cb25ceb
32 changed files with 3050 additions and 0 deletions
+36
View File
@@ -120,6 +120,42 @@ func (r *{{ export $.Endpoint.Entrypoint $a.Name }}) Fill(req *http.Request) (er
{{- end }}
{{ if $a.Params.Post }}
{
// Caching 32MB to memory, the rest to disk
if err = req.ParseMultipartForm(32 << 20); err != nil && err != http.ErrNotMultipart {
return err
} else if err == nil {
// Multipart params
{{ range $p := $a.Params.Post }}
{{ if $p.IsUpload }}
// Ignoring {{ $p.Name }} as its handled in the POST params section
{{- else }}
{{- if or $p.HasExplicitParser }}
if val, ok := req.MultipartForm.Value["{{ $p.Name }}[]"]; ok {
r.{{ export $p.Name }}, err = {{ $p.Parser "val" }}
if err != nil {
return err
}
} else if val, ok := req.MultipartForm.Value["{{ $p.Name }}"]; ok {
r.{{ export $p.Name }}, err = {{ $p.Parser "val" }}
if err != nil {
return err
}
}
{{- else if not $p.IsSlice }}
if val, ok := req.MultipartForm.Value["{{ $p.Name }}"]; ok && len(val) > 0 {
r.{{ export $p.Name }}, err = {{ $p.Parser "val[0]" }}
if err != nil {
return err
}
}
{{- end }}
{{- end }}
{{- end }}
}
}
{
if err = req.ParseForm(); err != nil {
return err