Mutated ServerHttpRequest returns native request correctly
Closes gh-26304
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -236,7 +236,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getNativeRequest() {
|
||||
return (T) this.originalRequest;
|
||||
return ServerHttpRequestDecorator.getNativeRequest(this.originalRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -120,6 +120,28 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the native request of the underlying server API, if possible,
|
||||
* also unwrapping {@link ServerHttpRequestDecorator} if necessary.
|
||||
* @param request the request to check
|
||||
* @param <T> the expected native request type
|
||||
* @throws IllegalArgumentException if the native request can't be obtained
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static <T> T getNativeRequest(ServerHttpRequest request) {
|
||||
if (request instanceof AbstractServerHttpRequest) {
|
||||
return ((AbstractServerHttpRequest) request).getNativeRequest();
|
||||
}
|
||||
else if (request instanceof ServerHttpRequestDecorator) {
|
||||
return getNativeRequest(((ServerHttpRequestDecorator) request).getDelegate());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't find native request in " + request.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,6 +110,28 @@ public class ServerHttpResponseDecorator implements ServerHttpResponse {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the native response of the underlying server API, if possible,
|
||||
* also unwrapping {@link ServerHttpResponseDecorator} if necessary.
|
||||
* @param response the response to check
|
||||
* @param <T> the expected native response type
|
||||
* @throws IllegalArgumentException if the native response can't be obtained
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static <T> T getNativeResponse(ServerHttpResponse response) {
|
||||
if (response instanceof AbstractServerHttpResponse) {
|
||||
return ((AbstractServerHttpResponse) response).getNativeResponse();
|
||||
}
|
||||
else if (response instanceof ServerHttpResponseDecorator) {
|
||||
return getNativeResponse(((ServerHttpResponseDecorator) response).getDelegate());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't find native response in " + response.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
|
||||
|
||||
Reference in New Issue
Block a user