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

A bug of header adding and getting in OpenFeign RequestInterceptor #760

Closed
HaojunRen opened this issue Sep 28, 2022 · 6 comments
Closed
Assignees

Comments

@HaojunRen
Copy link

HaojunRen commented Sep 28, 2022

Describe the bug
If we add add a header named abc with value {x:1.0,y:1.1} to OpenFeign RestTemplate, and get it to print, the final value will be {x:1.0,y}. That means :1.1 is lost.

This issue happens on Spring Cloud 2021.0.4.0, Spring Cloud 2020.0.6 and Hoxton.SR12 works fine.

Please take a look for it. Thanks

Sample

RequestInterceptor code as follows

import feign.RequestInterceptor;
import feign.RequestTemplate;

public class MyRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        String headerName = "abc";
        String headerValue = "{x:1.0,y:1.1}";
        
        System.out.println("--- Before adding: " + headerName + " = " + headerValue);
        
        requestTemplate.header(headerName, headerValue);
        
        String headerValueInRequestTemplate = requestTemplate.headers().get(headerName).toString();
        
        System.out.println("=== Get value after Adding: " + headerName + " = " + headerValueInRequestTemplate);
    }
}

Create the bean in your configuration

@Bean
public MyRequestInterceptor myRequestInterceptor() {
    return new MyRequestInterceptor();
 }
@HaojunRen
Copy link
Author

HaojunRen commented Sep 28, 2022

Refer to runing result

Spring Cloud 2021

1664346524750

Spring Cloud 2020

1664346274105

@HaojunRen
Copy link
Author

HaojunRen commented Sep 28, 2022

The header value starting with { will be considerd with an expression, it does not make sense,because header value will be often a json format.

1664349792390

@OlgaMaciaszek
Copy link
Collaborator

Hello, @HaojunRen. Thanks for providing the sample and sorry for not getting back to you earlier. I was able to reproduce the behaviour you've described. However, this happens while executing header(...) method on Feign RequestTemplate, which are part of the third-party Feign project. We only provide additional integrations and functionalities on top of it. You might want to create an issue in the OpenFeign/Feign repo instead.

@kdavisk6
Copy link

From the feign side, the issue here is the values being provided in the header are not valid JSON. The parameter names are not quoted properly, so the value in Feign is being truncated.

@HaojunRen
Copy link
Author

@OlgaMaciaszek
Copy link
Collaborator

@HaojunRen We're on Feign 12.5 on main (plans to upgrade to 13.0) and 12.4 on 4.0.x (plans to upgrade it to 12.5). 3.1.x will stay compatible with 11.x line, and its the OSS support is only for a few more days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants