Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

schaoukicoveo
Copy link

@schaoukicoveo schaoukicoveo commented Apr 27, 2023

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

@@ -15,13 +15,10 @@

import static feign.assertj.FeignAssertions.assertThat;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of unused import

Comment on lines +245 to +256
@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}")));
}

Copy link
Author

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.

Comment on lines +806 to +820
/**
* 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;
}

Copy link
Author

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

@schaoukicoveo schaoukicoveo changed the title Added support to add directly literals to the header Added support to add literals directly to the header Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Truncated JSON header value with @Headers
1 participant