@RequestHeader with null value set templated name as value
See original GitHub issueContinuation of https://github.com/spring-cloud/spring-cloud-netflix/issues/1594
Looks like bug or feature in RequestTemplate:
Object value = variables.get(var.toString());
if (value != null) {
builder.append(value);
} else {
builder.append('{').append(key).append('}');
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Spring MVC - @RequestHeader Examples - LogicBig
The defaultValue element is used as a fallback value when the request header specified by 'value' element is not provided or has an...
Read more >Unable to check null for header value in request
It has a method TryGetValues which can be used to safely retrieve the values of a header. String header = null; IEnumerable<String> headerValues ......
Read more >Spring @RequestHeader Annotation example - ViralPatel.net
If the header value that you specified does not exists in request, Spring will initialise the parameter with null value. In case you...
Read more >Set HTTP Header | Microsoft Learn
Assigns a value to an existing response and/or request header or adds a new response and/or request header. This template is available in ......
Read more >Mock API Response Templating - WireMock
The body file for a response can be selected dynamically by templating the file path: ... <key> - First value of a request...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
#724 has been accepted and removed headers that do not have a value. This should address your issue in the next release.
I did some detective work, the bug goes all the way back to the initial import from Netflix. It looks like there have been a attempts in the past to address other issues related in https://github.com/OpenFeign/feign/pull/326 and https://github.com/OpenFeign/feign/pull/348 and had a very specific use case it was trying to solve. The idea is to prevent accidental parameter expansion.
In my opinion, the current implementation feels fragile and my need some refactoring. However, the code is making an assumption that if there is no value for the parameter to be expanded, it assumes you want the literal. It also does not differentiate between variables within the body, or header, which I feel is where the issue truly lies.
One possible approach could be to introduce an
VariableExpanderStrategy
concept, with one implementation that does not replace the token if a value is missing and another that does.Thoughts?