-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added size limiter middleware * Added context type validation on JSON decoders * Improved BodyDecodeErrorHandler function (previously named as bodyDecodeErrorHandler)
- Loading branch information
1 parent
0699929
commit fb6f235
Showing
15 changed files
with
272 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package json | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// Inspired by: | ||
// https://www.alexedwards.net/blog/how-to-properly-parse-a-json-request-body | ||
|
||
// CheckContentType checks if the content type is JSON | ||
func CheckContentType(r *http.Request) bool { | ||
contentType := r.Header.Get("Content-Type") | ||
if contentType != "" { | ||
mediaType := strings.ToLower( | ||
strings.TrimSpace( | ||
strings.Split( | ||
contentType, | ||
";", | ||
)[0], | ||
), | ||
) | ||
return mediaType == "application/json" | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.