Skip to content

armandoalmeida/request-header-required-non-null

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workaround for @RequestHeader required with "null" value

The objective of this project is to create an alternative to this issue: spring-projects/spring-framework#23939

Requirements

See the pom.xml to more, but basically:

  • Spring Boot Web
  • Spring AOP

The idea

When there is a request header parameter required, the Spring framework validates only if this parameter is into the request, but not if its value is null.

So, to workaround this problem, use the annotation @RequestHeaderNonNull beside your @RequestHeader annotation, like this:

@RestController
public class ExampleController {

    @GetMapping("/")
    public String getSomething(@RequestHeader("X-Required-Header") @RequestHeaderNonNull String xRequiredHeader) {
        return "X-Required-Header: " + xRequiredHeader;
    }

}

Check the class RequestHeaderNonNullAspect to understand how it works...

About

Workaround for issue #23939 from Spring Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages