I am working on a Spring boot (3.2.2) project with Java 21. I have microservices in Spring boot which are deployed in AWS EKS and exposed via AWS API Gateway.
All was well, until recently I had to apply some logic based on the incoming origin of the request. For this reason, I implemented a Filter class implementing the WebFilter interface. I tried to check the request origin there as:
@Component
@Slf4j
public class OriginFilter implements WebFilter {
@Value("${access.control.allow.origin}")
private String whiteListedOrigins;
public static final String ORIGIN = "Origin";
public static final String DELIMITER = ",";
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
HttpHeaders requestHeaders = request.getHeaders();
String origin = requestHeaders.getFirst(ORIGIN);
}
However, I have observed that the supplied Origin header for POST and DELETE requests is successfully receieved in this code, while for GET requests the origin is received as null.
Earlier I was relying on my browsers for header but then I researched a bit and found that browser can skip sending Origin in certain cases. To overcome this, I have manually added an explicit Origin headers to my requests originating from my mobile client (based on React native and uses Axios for making HTTP calls).
However, the issue appears to be same, the GET request’s headers are overridden to null in Spring boot.
Does any one know the reason behind this. How can I recieve the headers correctly for GET request.
I also tried checking my APIG setting and nothing seem to be overriding the headers there.