Skip to content

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

@HaojunRen

Description

@HaojunRen

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();
 }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions