I'm experimenting with spring boot to learn. So I want to send a custom header to my backend spring boot server without using Spring Security. With curl it goes like this:
curl http://localhost:8080/data -H "Batman: Forever"
In my spring app I have a custom filter:
@Configuration
public class MyFilter extends OncePerRequestFilter {
private final Logger log = LoggerFactory.getLogger(getClass());
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String header = request.getHeader("Batman");
log.info("Batman: "+ header);
request.getHeaderNames().asIterator().forEachRemaining(s -> log.info(s));
filterChain.doFilter(request, response);
}
}
With curl I recieve the header 'Batman' but not with angular that goes like this:
getData(): Observable<any> {
const url = 'http://localhost:8080/data'
let headers_obj = new HttpHeaders()
headers_obj.append('Content-Type', 'application/json')
headers_obj.append('Batman', 'Forever')
const httpOptions = {
headers: headers_obj,
}
console.log('Provided user: ', this.username)
return this.http.get<any>(url, httpOptions)
}
I spent hours googling the issue without success. Thank you for any help