-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to add literals directly to the header #2028
Conversation
@@ -15,13 +15,10 @@ | |||
|
|||
import static feign.assertj.FeignAssertions.assertThat; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removal of unused import
@Test | ||
public void shouldNotResolveTemplateWithHeaderWithJsonLiteral() { | ||
String json = "{ \"foo\": \"bar\", \"hello\": \"world\"}"; | ||
RequestTemplate template = new RequestTemplate().method(HttpMethod.GET) | ||
.headerLiteral("A-Header", "{aHeader}"); | ||
|
||
template = template.resolve(mapOf("aHeader", json)); | ||
|
||
assertThat(template) | ||
.hasHeaders(entry("A-Header", Collections.singletonList("{aHeader}"))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sure that if a expression that is added as a literal will not be evaluated as an expression when trying to resolve.
/** | ||
* Validates that both the name and values are valid | ||
* | ||
* @param name of the header. | ||
* @param values for this header. | ||
* @return an Iterable of strings | ||
*/ | ||
private Iterable<String> validateHeaderValues(String name, Iterable<String> values) { | ||
if (name == null || name.isEmpty()) { | ||
throw new IllegalArgumentException("name is required."); | ||
} | ||
|
||
return values == null ? Collections.emptyList() : values; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide a private method that will contain the necessary validation for headers
Added support to add literals directly to the header.
In short, I exposed a public method that will provide a way to add literals directly to the header. Beforehand, a literal would never be evaluated/seen as one up until we try to create the
Template
object., it would be beneficial to have such a method call as it will prevent extra processing with trying to match a complex regex expression with something that wishes to be processed as literal and not an expression. This will provide a clearer and simpler way for end users to send literals, especially for json strings.Properly fixes #1464