mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-08-31 16:21:26 +02:00
fix: don't rely on content length header for optional json binding
This commit is contained in:
@@ -33,17 +33,13 @@ func BindJSON(c *gin.Context, value any) error {
|
||||
|
||||
// BindOptionalJSON accepts an empty body while normalizing valid input and classifying malformed JSON as invalid input
|
||||
func BindOptionalJSON(c *gin.Context, value any) error {
|
||||
if c.Request.ContentLength == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := requireJSONContentType(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := c.ShouldBindJSON(value)
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
if contentTypeErr := requireJSONContentType(c); contentTypeErr != nil {
|
||||
return contentTypeErr
|
||||
}
|
||||
if err = classifyBindingError(err); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user