I want to set the Content-Type header programatically. When I try this happens:

Caused by: feign.codec.EncodeException: Invalid mime type "{Content-Type}": does not contain '/'
    at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:346)
    at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:213)
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:72)
    at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:108)
    at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:301)
    at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:297)
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
    ... 27 common frames omitted
Caused by: org.springframework.http.InvalidMediaTypeException: Invalid mime type "{Content-Type}": does not contain '/'
    at org.springframework.http.MediaType.parseMediaType(MediaType.java:425)
    at org.springframework.http.MediaType.valueOf(MediaType.java:410)
    at org.springframework.cloud.netflix.feign.support.SpringEncoder.encode(SpringEncoder.java:64)
    at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:342)
    ... 33 common frames omitted
Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "{Content-Type}": does not contain '/'
    at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:239)
    at org.springframework.http.MediaType.parseMediaType(MediaType.java:422)
    ... 36 common frames omitted
@FeignClient("x")
public interface XClient {
    @RequestMapping(value = "/api/something/{id}", method = POST)
    void x(@RequestHeader("Content-Type") String contentType, @PathVariable("id") Integer id,
        @RequestBody InputStream inputStream);
}

I ended up having to set a X-Content-Type2 header and setting up one of these:

@Bean
public RequestInterceptor contentTypeFilter() {
    return (req) -> {
        req.header("Content-Type", req.headers().get("X-Content-Type2").iterator().next());
    };
}

I am using: spring-cloud-netflix-core-1.2.5.RELEASE.jar

Comment From: ryanjbaxter

I dont believe you can set it programmatically using @RequestHeader, I believe we only support doing it via the consumes property of @RequestMapping.

Comment From: sixcorners

Is it possible to add support? Would it be a good idea to feed it to the @RequestMapping annotation using SpEL?

Comment From: thomasharin

I have same problem. Can I know some due date for this issue? My FeignClient request need to resend some header param from client application so I need dynamic value of header param. Is some other option for this case? Thanks.

Comment From: spencergibb

@thomasharin no due date. You can always use a RequestInterceptor.

Comment From: thorstenfrank

This would have to be changed inside Spring MVC, am I right?

Comment From: alvessergio

Did you find any solution for it?

Comment From: juliofalbo

+1

Comment From: raizoor

\o