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

Dynamically set Content-Type via @RequestHeader #116

Open
sixcorners opened this issue May 1, 2017 · 8 comments
Open

Dynamically set Content-Type via @RequestHeader #116

sixcorners opened this issue May 1, 2017 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sixcorners
Copy link

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

@ryanjbaxter
Copy link
Contributor

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

@sixcorners
Copy link
Author

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

@spencergibb spencergibb changed the title Can't set Content-Type in Feign client Dynamically set Content-Type via @RequestHeader May 15, 2017
@thomasharin
Copy link

thomasharin commented Jul 27, 2017

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.

@spencergibb
Copy link
Member

spencergibb commented Aug 4, 2017

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

@thorstenfrank
Copy link

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

@alvessergio
Copy link

Did you find any solution for it?

@spencergibb spencergibb transferred this issue from spring-cloud/spring-cloud-netflix Jan 31, 2019
@spencergibb spencergibb added enhancement New feature or request help wanted Extra attention is needed labels Jan 31, 2019
@juliofalbo

This comment has been minimized.

@raizoor

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants