all repos — honk @ 0e627f0eab06c6b459836ee2dec02f7ea1f473b6

my fork of honk

relax form-data requiremnt for api
Ted Unangst tedu@tedunangst.com
Tue, 10 Nov 2020 23:11:50 -0500
commit

0e627f0eab06c6b459836ee2dec02f7ea1f473b6

parent

35c4c78c754770bacd5d0a1b06fe2749b1e5d63d

3 files changed, 15 insertions(+), 7 deletions(-)

jump to
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

=== next ++ Relax requirement for multipart/form-data posts in API. + + Dedupe blob file data. - Custom lingo for those who don't like honking.
M docs/honk.3docs/honk.3

@@ -67,7 +67,7 @@ The

.Fa action value should be .Dq honk . -Content type must be multipart/form-data. +Content type should be multipart/form-data if an attachment is included. The following values are recognized: .Bl -tag -width placename .It Fa noise
M web.goweb.go

@@ -1418,12 +1418,16 @@ return true

} func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) { + if !strings.HasPrefix(strings.ToLower(r.Header.Get("Content-Type")), "multipart/form-data") { + return nil, nil + } file, filehdr, err := r.FormFile("donk") if err != nil { - if err != http.ErrMissingFile { - log.Printf("error reading donk: %s", err) - http.Error(w, "error reading donk", http.StatusUnsupportedMediaType) + if err == http.ErrMissingFile { + return nil, nil } + log.Printf("error reading donk: %s", err) + http.Error(w, "error reading donk", http.StatusUnsupportedMediaType) return nil, err } var buf bytes.Buffer

@@ -2236,9 +2240,11 @@ w.Write([]byte(h.XID))

case "donk": d, err := submitdonk(w, r) if err != nil { - if err == http.ErrMissingFile { - http.Error(w, "missing donk", http.StatusBadRequest) - } + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + if d == nil { + http.Error(w, "missing donk", http.StatusBadRequest) return } w.Write([]byte(d.XID))