1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-09 22:44:36 +02:00
This commit is contained in:
binwiederhier 2022-12-29 09:57:42 -05:00
parent 66cb35b5fc
commit 57814cf855
8 changed files with 209 additions and 37 deletions
server

View file

@ -5,6 +5,7 @@ import (
"github.com/emersion/go-smtp"
"heckel.io/ntfy/log"
"heckel.io/ntfy/util"
"io"
"net/http"
"net/netip"
"strings"
@ -121,3 +122,15 @@ func extractIPAddress(r *http.Request, behindProxy bool) netip.Addr {
}
return ip
}
func readJSONWithLimit[T any](r io.ReadCloser, limit int) (*T, error) {
obj, err := util.ReadJSONWithLimit[T](r, limit)
if err == util.ErrInvalidJSON {
return nil, errHTTPBadRequestJSONInvalid
} else if err == util.ErrTooLargeJSON {
return nil, errHTTPEntityTooLargeJSONBody
} else if err != nil {
return nil, err
}
return obj, nil
}