mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-09 22:44:36 +02:00
Tests
This commit is contained in:
parent
66cb35b5fc
commit
57814cf855
8 changed files with 209 additions and 37 deletions
server
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue