mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-07 17:02:29 +01:00
fix (middleware): bodyparser must not return an error if no body
This commit is contained in:
parent
bd9deb858d
commit
0acf94ce0c
1 changed files with 4 additions and 1 deletions
|
|
@ -11,12 +11,15 @@ import (
|
||||||
|
|
||||||
func BodyParser(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *App, res http.ResponseWriter, req *http.Request) {
|
func BodyParser(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||||
extractBody := func(req *http.Request) (map[string]interface{}, error) {
|
extractBody := func(req *http.Request) (map[string]interface{}, error) {
|
||||||
var body map[string]interface{}
|
body := map[string]interface{}{}
|
||||||
byt, err := ioutil.ReadAll(req.Body)
|
byt, err := ioutil.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return body, err
|
return body, err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(byt, &body); err != nil {
|
if err := json.Unmarshal(byt, &body); err != nil {
|
||||||
|
if len(byt) == 0 {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return body, err
|
return body, err
|
||||||
}
|
}
|
||||||
return body, nil
|
return body, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue