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

Skip validation of content-type by TypedBody if body is empty #1094

Closed
kelchm opened this issue Nov 1, 2024 · 1 comment
Closed

Skip validation of content-type by TypedBody if body is empty #1094

kelchm opened this issue Nov 1, 2024 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@kelchm
Copy link

kelchm commented Nov 1, 2024

Feature Request

In some cases I'd like to be able to make the body of a request optional. This seems to work as expected with @TypedBody, with the exception of it enforcing a check for a Content-Type of application/json:

if (isApplicationJson(request.headers["content-type"]) === false)
throw new BadRequestException(
`Request body type is not "application/json".`,
);

I would argue that specifically in the case of a request with no body, there should be no expectation of a Content-Type header and therefore we should bypass this check. It would then be up to the validator to make a determination of whether this empty body is permissible.

@samchon samchon self-assigned this Nov 4, 2024
@samchon samchon added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Nov 4, 2024
@samchon
Copy link
Owner

samchon commented Nov 4, 2024

You are meaning that when the request body parameter type is optional, right?

samchon added a commit that referenced this issue Nov 11, 2024
Fix #1094: skip validation when no request body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
Status: Done
Development

No branches or pull requests

2 participants