Skip to content

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

Closed
@memoricab

Description

@memoricab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions