-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
"GET must not have a request body" exception with RestTemplate.exchange(...) and OkHttp3ClientHttpRequest.executeInternal() #32819
Comments
This sounds similar to #32612 but this should have been resolved in 6.1.6. Rather than discussing the possible reasons, could you provide us with a minimal sample application that reproduces the problem? |
Ok, will do a demo app repo and link it. Is that ok? |
Yes please! |
I've put together a complete minimal demo project that reproduces the problem: https://github.com/kamabulletone/okhttp-issue-demo Also I've created an endpoint GET |
Your sample application is using Spring Boot 3.2.3, which is using Spring Framework 6.1.4. Upgrading your sample application to Spring Boot 3.2.5 (and thus Spring Framework 6.1.6) works for me. I'm tempted to close this as a duplicate of #32612. Let me know if I'm missing something. |
Turns out we configured out service not correctly. Thank you for cooperation and investing your time! |
Thanks for letting us know. |
Out team recently upgraded out project from spring boot 3.1.9 to 3.2.3 (spring-framework from 6.0.17 to 6.1.6). After this upgrade we start getting "GET must not have a request body" on GET calls. We havent changed any configuration but versions of libs. We have the following RestTemplate configuration now:
I've erased some exception related messages. Code of out rest-service:
Using spring-boot 3.1.9 (spring-framework 6.0.17) worked just fine. But after moving to spring-boot 3.2.3 (spring-framework 6.1.6) we got following errors with stacktrace:
I've looked up changes made between these 2 spring boot and spring framework version and in spring-framework (spring-web) there was an issue that affected OkHttp3ClientHttpRequest.java
Before this issue
spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequest.java
hadexecuteInternal(HttpHeaders headers, byte[] content)
signature and implemented like this:And
OkHttp3ClientHttpRequestFactory.buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method)
created request body when and only whencontent.length > 0
or http method requires request body:But after resolving of that issue implementation changed and new request body wrapper was implemented. THe OkHttp3ClientHttpRequest.executeInternal(...) method signature changed to
ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body)
:This implementation doesnt check Body.bufferedOutput if it's empty so creates request body event if there isn't any content bytes. I've run debugging to this point during GET request and this is the result:
As you can see bufferedOutput is empty but request body created. I assume just add extra condition after checking
if body is null
like this:The text was updated successfully, but these errors were encountered: