Update Content-Length when body changed by Interceptor#33459
Update Content-Length when body changed by Interceptor#33459imzhoukunqiang wants to merge 3 commits intospring-projects:mainfrom
Conversation
|
I am not sure we should do this. Do we really set the content length header in all cases and for all converters? If an interceptor is changing the request body I would argue it needs to change the content type as well as the content length of it was set already. |
I agree with your point of view. I'm not sure whether setting And if after executing the interceptor chain, the |
|
Your description makes sense. However, isn't your PR setting it in all cases? |
Updated. |
|
Thanks for your contribution @imzhoukunqiang , this is now merged. |
Hi maintainers, while working with the framework, I discovered a bug that I believe warrants attention.
In the
org.springframework.http.client.InterceptingClientHttpRequest, the request body may be changed byinterceptors, butContent-Lengthin the request headers didn't. This may cause the server receive the incorrect request body.I created a simple demo to show this bug . DEMO
The fix for this is to reset the
Content-Lengthbefore sending the request atorg.springframework.http.client.InterceptingClientHttpRequest.InterceptingRequestExecution#execute