Skip to content

Commit 235fa11

Browse files
committed
Changes for Supported methods.
Signed-off-by: Mario Daniel Ruiz Saavedra <desiderantes93@gmail.com>
1 parent 6c71421 commit 235fa11

7 files changed

Lines changed: 25 additions & 19 deletions

File tree

spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ protected void prepareConnection(HttpURLConnection connection, String httpMethod
155155

156156
boolean mayWrite =
157157
("POST".equals(httpMethod) || "PUT".equals(httpMethod) ||
158-
"PATCH".equals(httpMethod) || "DELETE".equals(httpMethod));
158+
"PATCH".equals(httpMethod) || "DELETE".equals(httpMethod) ||
159+
"QUERY".equals(httpMethod));
159160

160161
connection.setDoInput(true);
161162
connection.setInstanceFollowRedirects("GET".equals(httpMethod));

spring-web/src/main/java/org/springframework/web/filter/reactive/HiddenHttpMethodFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class HiddenHttpMethodFilter implements WebFilter {
4848

4949
private static final List<HttpMethod> ALLOWED_METHODS =
50-
List.of(HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH);
50+
List.of(HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.QUERY);
5151

5252
/** Default name of the form parameter with the HTTP method to use. */
5353
public static final String DEFAULT_METHOD_PARAMETER_NAME = "_method";

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestMethodsRequestCondition.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ else if (isEmpty()) {
157157
if (requestMethod.equals(RequestMethod.HEAD) && getMethods().contains(RequestMethod.GET)) {
158158
return requestMethodConditionCache.get(HttpMethod.GET);
159159
}
160-
if (requestMethod.equals(RequestMethod.HEAD) && getMethods().contains(RequestMethod.QUERY)) {
161-
return requestMethodConditionCache.get(HttpMethod.QUERY);
162-
}
163160
}
164161
return null;
165162
}
@@ -187,9 +184,6 @@ else if (this.methods.size() == 1) {
187184
else if (this.methods.contains(RequestMethod.GET) && other.methods.contains(RequestMethod.HEAD)) {
188185
return 1;
189186
}
190-
else if (this.methods.contains(RequestMethod.QUERY) && other.methods.contains(RequestMethod.HEAD)) {
191-
return 1;
192-
}
193187
}
194188
return 0;
195189
}

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
public abstract class AbstractMessageReaderArgumentResolver extends HandlerMethodArgumentResolverSupport {
7575

7676
private static final Set<HttpMethod> SUPPORTED_METHODS =
77-
Set.of(HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH);
77+
Set.of(HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.QUERY);
7878

7979

8080
private final List<HttpMessageReader<?>> messageReaders;

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ else if (isEmpty()) {
162162
if (requestMethod.equals(RequestMethod.HEAD) && getMethods().contains(RequestMethod.GET)) {
163163
return requestMethodConditionCache.get(HttpMethod.GET.name());
164164
}
165-
if (requestMethod.equals(RequestMethod.HEAD) && getMethods().contains(RequestMethod.QUERY)) {
166-
return requestMethodConditionCache.get(HttpMethod.QUERY.name());
167-
}
168165
}
169166
return null;
170167
}
@@ -192,9 +189,6 @@ else if (this.methods.size() == 1) {
192189
else if (this.methods.contains(RequestMethod.GET) && other.methods.contains(RequestMethod.HEAD)) {
193190
return 1;
194191
}
195-
else if (this.methods.contains(RequestMethod.QUERY) && other.methods.contains(RequestMethod.HEAD)) {
196-
return 1;
197-
}
198192
}
199193
return 0;
200194
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ private Map<String, MultiValueMap<String, String>> extractMatrixVariables(
253253
if (helper.hasMethodsMismatch()) {
254254
Set<String> methods = helper.getAllowedMethods();
255255
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
256-
Set<MediaType> mediaTypes = helper.getConsumablePatchMediaTypes();
257-
HttpOptionsHandler handler = new HttpOptionsHandler(methods, mediaTypes);
256+
Set<MediaType> patchMediaTypes = helper.getConsumablePatchMediaTypes();
257+
Set<MediaType> queryMediaTypes = helper.getConsumableQueryMediaTypes();
258+
HttpOptionsHandler handler = new HttpOptionsHandler(methods, patchMediaTypes, queryMediaTypes);
258259
return new HandlerMethod(handler, HTTP_OPTIONS_HANDLE_METHOD);
259260
}
260261
throw new HttpRequestMethodNotSupportedException(request.getMethod(), methods);
@@ -437,6 +438,21 @@ public Set<MediaType> getConsumablePatchMediaTypes() {
437438
return result;
438439
}
439440

441+
/**
442+
* Return declared "consumable" types but only among those that have
443+
* QUERY specified, or that have no methods at all.
444+
*/
445+
public Set<MediaType> getConsumableQueryMediaTypes() {
446+
Set<MediaType> result = new LinkedHashSet<>();
447+
for (PartialMatch match : this.partialMatches) {
448+
Set<RequestMethod> methods = match.getInfo().getMethodsCondition().getMethods();
449+
if (methods.isEmpty() || methods.contains(RequestMethod.QUERY)) {
450+
result.addAll(match.getInfo().getConsumesCondition().getConsumableMediaTypes());
451+
}
452+
}
453+
return result;
454+
}
455+
440456

441457
/**
442458
* Container for a RequestMappingInfo that matches the URL path at least.
@@ -501,9 +517,10 @@ private static class HttpOptionsHandler {
501517

502518
private final HttpHeaders headers = new HttpHeaders();
503519

504-
public HttpOptionsHandler(Set<String> declaredMethods, Set<MediaType> acceptPatch) {
520+
public HttpOptionsHandler(Set<String> declaredMethods, Set<MediaType> acceptPatch, Set<MediaType> acceptQuery) {
505521
this.headers.setAllow(initAllowedHttpMethods(declaredMethods));
506522
this.headers.setAcceptPatch(new ArrayList<>(acceptPatch));
523+
this.headers.setAcceptQuery(new ArrayList<>(acceptQuery));
507524
}
508525

509526
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
7474
protected enum ConverterType { BASE, GENERIC, SMART };
7575

7676

77-
private static final Set<HttpMethod> SUPPORTED_METHODS = Set.of(HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH);
77+
private static final Set<HttpMethod> SUPPORTED_METHODS = Set.of(HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.QUERY);
7878

7979
private static final Object NO_VALUE = new Object();
8080

0 commit comments

Comments
 (0)