-
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
A bug of header adding and getting in OpenFeign RequestInterceptor #1987
Comments
Hi! Please try to put keys to doublequoters, it works: @Test
public void headerWithJSONValue() {
RequestTemplate template = new RequestTemplate()
.header("key", "{\"x\":1.0,\"y\":1.1}");
assertThat(template.headers()).hasSize(1);
assertThat(template.headers().keySet()).containsExactly("key");
assertThat(template.headers().get("key")).containsExactly("{\"x\":1.0,\"y\":1.1}");
} |
It does not make sense, that means i should add double-quoters to every header value with json format one by one? |
This is JSON's rule: string are wrapped double quotes, both in keys and values. And as far as I guess this rule is used to avoid processing of header value, see Request Headers Expansion that uses curly brackets like JSON does. |
As @radio-rogal has stated, Feign supports expression based headers. This means you can use URI templates in your header values and have them resolved at execution time. The incompatibility you are seeing is related to the use of JSON as a header value, which conflicts with the URI Template specification where dynamic expressions are wrapped in braces If you chose to use Feign and require JSON based header values, you will need to quote them as discussed. |
I try : |
It doesn't work in version: |
This change adds a new method RequestTemplate#headerLiteral which allows adding headers which are not interpreted as Template expressions. This allows adding empty JSON objects to headers in RequestInterceptor implementations. Fixes OpenFeign#2252, OpenFeign#1987
* Allows adding literal header values to RequestTemplate This change adds a new method RequestTemplate#headerLiteral which allows adding headers which are not interpreted as Template expressions. This allows adding empty JSON objects to headers in RequestInterceptor implementations. Fixes #2252, #1987 * Update RequestTemplate.java --------- Co-authored-by: Marvin <velo@users.noreply.github.com>
Fixed in #2471 |
* Allows adding literal header values to RequestTemplate This change adds a new method RequestTemplate#headerLiteral which allows adding headers which are not interpreted as Template expressions. This allows adding empty JSON objects to headers in RequestInterceptor implementations. Fixes #2252, #1987 * Update RequestTemplate.java --------- Co-authored-by: Marvin <velo@users.noreply.github.com>
* Allows adding literal header values to RequestTemplate This change adds a new method RequestTemplate#headerLiteral which allows adding headers which are not interpreted as Template expressions. This allows adding empty JSON objects to headers in RequestInterceptor implementations. Fixes #2252, #1987 * Update RequestTemplate.java --------- Co-authored-by: Marvin <velo@users.noreply.github.com>
Refer to the following issue at Spring Cloud community
spring-cloud/spring-cloud-openfeign#760
The text was updated successfully, but these errors were encountered: