Skip to content

Commit

Permalink
fix: multipart/form-data support
Browse files Browse the repository at this point in the history
close #100
  • Loading branch information
ncarlier committed Aug 10, 2024
1 parent 321ad7e commit 361770b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,24 @@ func triggerWebhook(w http.ResponseWriter, r *http.Request) {
ct := r.Header.Get("Content-Type")
if ct != "" {
mediatype, _, _ := mime.ParseMediaType(ct)
if strings.HasPrefix(mediatype, "text/") || mediatype == "application/json" {
switch {
case mediatype == "application/json", strings.HasPrefix(mediatype, "text/"):
body, err = io.ReadAll(r.Body)
if err != nil {
msg := "unable to read request body"
slog.Error(msg, "err", err)
http.Error(w, msg, http.StatusBadRequest)
return
}
case mediatype == "multipart/form-data":
if err := r.ParseMultipartForm(8 << 20); err != nil {
msg := "unable to parse multipart/form-data"
slog.Error(msg, "err", err)
http.Error(w, msg, http.StatusBadRequest)
return
}
default:
slog.Debug("unsuported media type", "media_type", mediatype)
}
}

Expand Down

0 comments on commit 361770b

Please sign in to comment.