relax form-data requiremnt for api
This commit is contained in:
parent
59b5b61890
commit
57822ea89d
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
=== next
|
=== next
|
||||||
|
|
||||||
|
+ Relax requirement for multipart/form-data posts in API.
|
||||||
|
|
||||||
+ Dedupe blob file data.
|
+ Dedupe blob file data.
|
||||||
|
|
||||||
- Custom lingo for those who don't like honking.
|
- Custom lingo for those who don't like honking.
|
||||||
|
|
|
@ -67,7 +67,7 @@ The
|
||||||
.Fa action
|
.Fa action
|
||||||
value should be
|
value should be
|
||||||
.Dq honk .
|
.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:
|
The following values are recognized:
|
||||||
.Bl -tag -width placename
|
.Bl -tag -width placename
|
||||||
.It Fa noise
|
.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) {
|
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")
|
file, filehdr, err := r.FormFile("donk")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != http.ErrMissingFile {
|
if err == http.ErrMissingFile {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
log.Printf("error reading donk: %s", err)
|
log.Printf("error reading donk: %s", err)
|
||||||
http.Error(w, "error reading donk", http.StatusUnsupportedMediaType)
|
http.Error(w, "error reading donk", http.StatusUnsupportedMediaType)
|
||||||
}
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -2236,9 +2240,11 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
|
||||||
case "donk":
|
case "donk":
|
||||||
d, err := submitdonk(w, r)
|
d, err := submitdonk(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == http.ErrMissingFile {
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
http.Error(w, "missing donk", http.StatusBadRequest)
|
return
|
||||||
}
|
}
|
||||||
|
if d == nil {
|
||||||
|
http.Error(w, "missing donk", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write([]byte(d.XID))
|
w.Write([]byte(d.XID))
|
||||||
|
|
Loading…
Reference in New Issue