mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
Avoid http - web.utils package cycle
Closes gh-35952
This commit is contained in:
+9
-5
@@ -50,7 +50,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* {@link ServerHttpRequest} implementation that is based on a {@link HttpServletRequest}.
|
||||
@@ -129,15 +128,15 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
if (hasQuery) {
|
||||
String requestURL = servletRequest.getRequestURL().toString();
|
||||
try {
|
||||
// Maybe malformed query, try to parse and encode it
|
||||
query = UriComponentsBuilder.fromUriString("?" + query).build().toUri().getRawQuery();
|
||||
return new URI(servletRequest.getRequestURL().toString() + "?" + query);
|
||||
// Maybe malformed query, try to encode it
|
||||
return new URI(requestURL + "?" + encodeQuery(query));
|
||||
}
|
||||
catch (URISyntaxException ex2) {
|
||||
try {
|
||||
// Try leaving it out
|
||||
return new URI(servletRequest.getRequestURL().toString());
|
||||
return new URI(requestURL);
|
||||
}
|
||||
catch (URISyntaxException ex3) {
|
||||
// ignore
|
||||
@@ -149,6 +148,11 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
||||
}
|
||||
}
|
||||
|
||||
private static String encodeQuery(String query) throws URISyntaxException {
|
||||
// Avoid package cycle with web.utils
|
||||
return new URI(null, null, "", query, null).getRawQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
if (this.headers == null) {
|
||||
|
||||
+9
-5
@@ -50,7 +50,6 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Adapt {@link ServerHttpRequest} to the Servlet {@link HttpServletRequest}.
|
||||
@@ -139,15 +138,15 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
if (hasQuery) {
|
||||
String requestURL = servletRequest.getRequestURL().toString();
|
||||
try {
|
||||
// Maybe malformed query, try to parse and encode it
|
||||
query = UriComponentsBuilder.fromUriString("?" + query).build().toUri().getRawQuery();
|
||||
return new URI(servletRequest.getRequestURL().toString() + "?" + query);
|
||||
// Maybe malformed query, try to encode it
|
||||
return new URI(requestURL + "?" + encodeQuery(query));
|
||||
}
|
||||
catch (URISyntaxException ex2) {
|
||||
try {
|
||||
// Try leaving it out
|
||||
return new URI(servletRequest.getRequestURL().toString());
|
||||
return new URI(requestURL);
|
||||
}
|
||||
catch (URISyntaxException ex3) {
|
||||
// ignore
|
||||
@@ -159,6 +158,11 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
}
|
||||
|
||||
private static String encodeQuery(String query) throws URISyntaxException {
|
||||
// Avoid package cycle with web.utils
|
||||
return new URI(null, null, "", query, null).getRawQuery();
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private static HttpHeaders initHeaders(HttpHeaders headerValues, HttpServletRequest request) {
|
||||
HttpHeaders headers = null;
|
||||
|
||||
Reference in New Issue
Block a user