-
Notifications
You must be signed in to change notification settings - Fork 38.5k
PATCH request is forbidden by RestClient
but allowed by WebTestClient
#31590
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
Comments
RestClient
but allowed by WebTestClient
Spring Boot's Switching to the more modern Java HttpClient fixes it: @PostConstruct
private void buildRestClient() {
restClient = restClientBuilder.baseUrl("http://localhost:" + port)
.requestFactory(new JdkClientHttpRequestFactory())
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
} |
Wouldn't it make sense to change the default client? |
@poutsma Thanks very much for your reply, I've confirmed that switching the request factory resolves the problem. Given that |
FWIW, It is because Boot uses the same There are plans to improve the situation, see spring-projects/spring-boot#36266 |
Uh oh!
There was an error while loading. Please reload this page.
Affects: spring 6.1.0-RC2 with spring boot 3.2.0-RC2 and JDK21
Description
I've attached a sample Spring Boot application with a single endpoint that accepts PATCH requests. When the endpoint is invoked with a PATCH request from a
WebTestClient
it is allowed, but when it is invoked with a PATCH request from aRestClient
, it fails with the following exceptionIn
SecurityConfiguration.java
I've added PATCH to the allowed methods, so I guessRestClient
is ignoring this configuration.Steps to Reproduce
demo.zip
The application contains 2 integration tests, one of which invokes the endpoint with a
RestClient
and the other usesWebTestClient
. The latter test passes, but the former fails.The text was updated successfully, but these errors were encountered: