-
-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config to enforce content types strictly #2255
Conversation
This is valuable for being able to unconditionally use formParams in an application without risking consuming the body stream on requests where the client did not send form params.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2255 +/- ##
============================================
- Coverage 86.42% 86.32% -0.10%
- Complexity 1299 1309 +10
============================================
Files 148 148
Lines 4029 4038 +9
Branches 504 508 +4
============================================
+ Hits 3482 3486 +4
- Misses 331 333 +2
- Partials 216 219 +3 ☔ View full report in Codecov by Sentry. |
/** Returns true if request is application/x-www-form-urlencoded. */ | ||
fun isFormUrlencoded(): Boolean = header(Header.CONTENT_TYPE)?.lowercase(Locale.ROOT)?.contains("application/x-www-form-urlencoded") == true | ||
|
||
/** Returns true if request is application/x-www-form-urlencoded. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Returns true if request is application/x-www-form-urlencoded. */ | |
/** Returns true if request is application/json. */ |
I do however wonder if you should use startsWith
for each value in the collection as usually content types can have definitions of character encoding etc in it, but it however should start with application/json. ie application/json; charset=iso-8859-1
This is correct per specification https://www.rfc-editor.org/rfc/rfc9110#media.type
Thanks @maths22, sorry about the long wait! |
This is valuable for being able to unconditionally use formParams
in an application without risking consuming the body stream on
requests where the client did not send form params.
For bodyAsClass/bodyStreamAsClass, this will throw a BadRequestResponse when trying to convert a non-JSON body to a class. For formParams and friends, the formParam list will be empty when trying to read form params from a request with a non-form-param content type.