Skip to content

Dynamically set Content-Type via @RequestHeader #116

Open
@sixcorners

Description

@sixcorners

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions