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

Why required request headers e.g. strings - are not treated as missing if they are blank? #28200

Closed
memoricab opened this issue Mar 19, 2022 · 4 comments

Comments

@memoricab
Copy link

Hello

When I read the below comments I understand that if a header is blank it is treated as missing regardless of thinking of the Key-Value concept.

For example, when we request a string header, even it is a blank string the controller does not respond as a bad request.

if the header is missing in the request, maybe I am assuming for this condition that a blank string does not mean missing header?
I wish we could somehow mention that regardless of the value it checks only the presence of the key of the header.

* Whether the header is required.
* <p>Defaults to {@code true}, leading to an exception being thrown
* if the header is missing in the request. Switch this to
* {@code false} if you prefer a {@code null} value if the header is
* not present in the request.
* <p>Alternatively, provide a {@link #defaultValue}, which implicitly
* sets this flag to {@code false}.
*/
boolean required() default true;

Disclosure:
I am aware of Spring 5.3+, for type conversions it works very well, but in my case is without type conversion. i.e. requesting string header and no type conversion.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 19, 2022
@memoricab memoricab changed the title Why required request headers are not treated as missing if they are blank? Why required request headers e.g. strings - are not treated as missing if they are blank? Mar 19, 2022
@rstoyanchev
Copy link
Contributor

The header is indeed considered present but without a value. In the case where type conversion is required, it can "hide" the original empty value, and hence the change in 5.3 with #23939. We could improve the Javadoc for this.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Apr 25, 2022
@rstoyanchev
Copy link
Contributor

As to the question, why empty is not treated as missing, it really depends on your use case and perspective. There have been many discussions on the subject, and changing behavior will only lead to regressions for others.

@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label May 2, 2022
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants