feign icon indicating copy to clipboard operation
feign copied to clipboard

Default Client does not include Content-Length header for POST with Empty Body

Open brennerm opened this issue 4 years ago • 11 comments

We are using Feign 10.7.4 to execute a POST request with an empty body. In this case Feign does not add a Content-Length header to the request. According to the HTTP specification this is fine but some proxies, in our case Azure API Management, do not accept POST request with no Content-Length header. Would it be possible to add a Content-Length: 0 header to PATCH, POST and PUT requests with an empty body?

Further context:

  • https://stackoverflow.com/a/4198969
  • https://github.com/request/request/issues/89
  • https://github.com/urllib3/urllib3/issues/555
  • https://github.com/gatling/gatling/issues/3648

brennerm avatar May 19 '20 10:05 brennerm

Should be a simple change around this https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/Client.java#L189

What client are you using? Default one? if so, i gave you the correct link.

velo avatar May 19 '20 21:05 velo

We are including spring-cloud-openfeign so I suppose we use the FeignBlockingLoadBalancerClient client class.

brennerm avatar May 20 '20 11:05 brennerm

@brennerm can you please confirm with the Spring Cloud team that they are passing this through to us first?

kdavisk6 avatar May 30 '20 12:05 kdavisk6

In this case, only the default Client implementation is out of compliance. I'm going to update the title of this issue to reference that class and mark this as a bug.

kdavisk6 avatar Dec 29 '20 17:12 kdavisk6

Is there any workaround for this??

ameenudheenirshad avatar May 11 '21 10:05 ameenudheenirshad

@kdavisk6 still need help for this?

MazizEsa avatar May 29 '21 09:05 MazizEsa

I had the same problem, and solved sending an empty string.

raphmello avatar Aug 16 '21 14:08 raphmello

If you are using POST/PUT method with RequestParam, instead of this, try using Request body, cause with empty body Feign Client will send Content-Length: 0, and you will face "Length Required" problem

Yerden01 avatar Nov 01 '21 21:11 Yerden01

Have the same problem

alexey-plotnikoff avatar Dec 16 '21 15:12 alexey-plotnikoff

Also having this issue. Any idea on an ETA of a fix?

tcolombo08 avatar Jul 11 '22 20:07 tcolombo08

hi @tcolombo08 feign is mainly driven by volunteer work. ETA depends on someone that is affected by this issue getting involved.

velo avatar Jul 11 '22 22:07 velo