Skip to content
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

feat: warn when json validator does not find a content type in the request #3707

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/validator/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const validator = <
switch (target) {
case 'json':
if (!contentType || !jsonRegex.test(contentType)) {
const message = 'missing Content-Type header "application/json"'
throw new HTTPException(415, { message })
Soviut marked this conversation as resolved.
Show resolved Hide resolved
break
}
try {
Expand All @@ -86,6 +88,8 @@ export const validator = <
!contentType ||
!(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))
) {
const message = 'missing Content-Type header "application/x-www-form-encoded"'
throw new HTTPException(415, { message })
break
}

Expand Down