relax form-data requiremnt for api
This commit is contained in:
parent
59b5b61890
commit
57822ea89d
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
14
web.go
14
web.go
|
@ -1418,12 +1418,16 @@ func canedithonk(user *WhatAbout, honk *Honk) bool {
|
|||
}
|
||||
|
||||
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 {
|
||||
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 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
|
|||
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))
|
||||
|
|
Loading…
Reference in New Issue