Improve Jetty 10 check on client-side

Before this commit, JettyClientHttpResponse checked for the presence of
a server-side class to determine whether it is running on Jetty 10.
Unfortunately, that class is not necessarily present when just using the
Jetty client.

This commit improves the Jetty 10 check, so that it also works when
the Jetty client is used without the server.

Closes gh-27136
This commit is contained in:
Arjen Poutsma 2021-07-06 11:03:09 +02:00
parent cb251347c3
commit 94f56a2684
1 changed files with 12 additions and 3 deletions

View File

@ -33,7 +33,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -53,8 +52,7 @@ class JettyClientHttpResponse implements ClientHttpResponse {
private static final ClassLoader loader = JettyClientHttpResponse.class.getClassLoader();
private static final boolean jetty10Present = ClassUtils.isPresent(
"org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer", loader);
private static final boolean jetty10Present;
private final ReactiveResponse reactiveResponse;
@ -64,6 +62,17 @@ class JettyClientHttpResponse implements ClientHttpResponse {
private final HttpHeaders headers;
static {
try {
Class<?> httpFieldsClass = loader.loadClass("org.eclipse.jetty.http.HttpFields");
jetty10Present = httpFieldsClass.isInterface();
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException("No compatible Jetty version found", ex);
}
}
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
this.reactiveResponse = reactiveResponse;
this.content = Flux.from(content);