question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@RequestHeader with null value set templated name as value

See original GitHub issue

Continuation 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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kdavisk6commented, Jul 18, 2018

#724 has been accepted and removed headers that do not have a value. This should address your issue in the next release.

1reaction
kdavisk6commented, Jun 28, 2018

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.

public class Expander {
   public String expand(String template, Map<String, ?> uriVariables, VariableExpanderStrategy strategy) {
      ...
   }
}
public class RemoveMissingExpanderStrategy implements VariableExpanderStrategy {
   public String expand(String template, Map<String, ?> uriVariables) {
      // if no variable exists for the token, remove it
   }
}
public class TokenLiteralExpanderStrategy implements VariableExpanderStrategy {
   public String expand(String template, Map<String, ?> uriVariables) {
      // if no variable exists for the token, treat the token as a literal string
   }
}

Thoughts?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found