/** * Determine whether this {@code HttpMethod} matches the given * method value. * @param method the method value as a String * @return {@code true} if it matches, {@code false} otherwise * @since 4.2.4 */ public boolean matches(String method) { return (this == resolve(method)); }
/** * Determine whether this {@code HttpMethod} matches the given * method value. * @param method the method value as a String * @return {@code true} if it matches, {@code false} otherwise * @since 4.2.4 */ public boolean matches(String method) { return (this == resolve(method)); }
@Override @Nullable public HttpMethod getMethod() { return HttpMethod.resolve(this.servletRequest.getMethod()); }
/** * Get the HTTP method. * @return the HTTP method as an HttpMethod enum value, or {@code null} * if not resolvable (e.g. in case of a non-standard HTTP method) */ @Nullable default HttpMethod method() { return HttpMethod.resolve(methodName()); }
@Override public HttpMethod getMethod() { HttpMethod method = HttpMethod.resolve(this.jettyRequest.getMethod()); Assert.state(method != null, "Method must not be null"); return method; }
/** * Return the HTTP method of the request. * @since 4.0.2 */ @Nullable public HttpMethod getHttpMethod() { return HttpMethod.resolve(getRequest().getMethod()); }
/** * Return the HTTP method of the request. * @return the HTTP method as an HttpMethod enum value, or {@code null} * if not resolvable (e.g. in case of a non-standard HTTP method) * @see #getMethodValue() * @see HttpMethod#resolve(String) */ @Nullable default HttpMethod getMethod() { return HttpMethod.resolve(getMethodValue()); }
/** * Return the value of the {@code Access-Control-Request-Method} request header. */ @Nullable public HttpMethod getAccessControlRequestMethod() { return HttpMethod.resolve(getFirst(ACCESS_CONTROL_REQUEST_METHOD)); }
@Override public HttpMethod getRequestMethod() { return HttpMethod.resolve(getRequest().getMethod()); }
/** * Return the actually supported HTTP methods as {@link HttpMethod} instances, * or {@code null} if not known. * @since 3.2 */ @Nullable public Set<HttpMethod> getSupportedHttpMethods() { if (this.supportedMethods == null) { return null; } List<HttpMethod> supportedMethods = new LinkedList<>(); for (String value : this.supportedMethods) { HttpMethod resolved = HttpMethod.resolve(value); if (resolved != null) { supportedMethods.add(resolved); } } return EnumSet.copyOf(supportedMethods); }
@Override public HttpMethod getRequestMethod() { return HttpMethod.resolve(getMethod()); }
/** * Return the value of the {@code Access-Control-Allow-Methods} response header. */ public List<HttpMethod> getAccessControlAllowMethods() { List<HttpMethod> result = new ArrayList<>(); String value = getFirst(ACCESS_CONTROL_ALLOW_METHODS); if (value != null) { String[] tokens = StringUtils.tokenizeToStringArray(value, ","); for (String token : tokens) { HttpMethod resolved = HttpMethod.resolve(token); if (resolved != null) { result.add(resolved); } } } return result; }
/** * Add an HTTP method to allow. */ public void addAllowedMethod(String method) { if (StringUtils.hasText(method)) { if (this.allowedMethods == null) { this.allowedMethods = new ArrayList<>(4); this.resolvedMethods = new ArrayList<>(4); } else if (this.allowedMethods == DEFAULT_PERMIT_METHODS) { setAllowedMethods(DEFAULT_PERMIT_METHODS); } this.allowedMethods.add(method); if (ALL.equals(method)) { this.resolvedMethods = null; } else if (this.resolvedMethods != null) { this.resolvedMethods.add(HttpMethod.resolve(method)); } } }
/** * Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"}, * {@code "PUT"}, etc. * <p>The special value {@code "*"} allows all methods. * <p>If not set, only {@code "GET"} and {@code "HEAD"} are allowed. * <p>By default this is not set. * <p><strong>Note:</strong> CORS checks use values from "Forwarded" * (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>), * "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers, * if present, in order to reflect the client-originated address. * Consider using the {@code ForwardedHeaderFilter} in order to choose from a * central place whether to extract and use, or to discard such headers. * See the Spring Framework reference for more on this filter. */ public void setAllowedMethods(@Nullable List<String> allowedMethods) { this.allowedMethods = (allowedMethods != null ? new ArrayList<>(allowedMethods) : null); if (!CollectionUtils.isEmpty(allowedMethods)) { this.resolvedMethods = new ArrayList<>(allowedMethods.size()); for (String method : allowedMethods) { if (ALL.equals(method)) { this.resolvedMethods = null; break; } this.resolvedMethods.add(HttpMethod.resolve(method)); } } else { this.resolvedMethods = DEFAULT_METHODS; } }
/** * Return the set of allowed {@link HttpMethod HTTP methods}, * as specified by the {@code Allow} header. * <p>Returns an empty set when the allowed methods are unspecified. */ public Set<HttpMethod> getAllow() { String value = getFirst(ALLOW); if (!StringUtils.isEmpty(value)) { String[] tokens = StringUtils.tokenizeToStringArray(value, ","); List<HttpMethod> result = new ArrayList<>(tokens.length); for (String token : tokens) { HttpMethod resolved = HttpMethod.resolve(token); if (resolved != null) { result.add(resolved); } } return EnumSet.copyOf(result); } else { return EnumSet.noneOf(HttpMethod.class); } }
/** * Return declared HTTP methods. */ public Set<HttpMethod> getAllowedMethods() { return this.partialMatches.stream(). flatMap(m -> m.getInfo().getMethodsCondition().getMethods().stream()). map(requestMethod -> HttpMethod.resolve(requestMethod.name())). collect(Collectors.toSet()); }
/** * Override the parent class implementation in order to intercept PATCH requests. */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpMethod httpMethod = HttpMethod.resolve(request.getMethod()); if (httpMethod == HttpMethod.PATCH || httpMethod == null) { processRequest(request, response); } else { super.service(request, response); } }
private ServerWebExchange mapExchange(ServerWebExchange exchange, String methodParamValue) { HttpMethod httpMethod = HttpMethod.resolve(methodParamValue.toUpperCase(Locale.ENGLISH)); Assert.notNull(httpMethod, () -> "HttpMethod '" + methodParamValue + "' not supported"); if (ALLOWED_METHODS.contains(httpMethod)) { return exchange.mutate().request(builder -> builder.method(httpMethod)).build(); } else { return exchange; } }
@Override public HttpMethod getRequestMethod() { return HttpMethod.resolve(getMethod()); }
@Nullable private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue); if (httpMethod != null) { for (RequestMethod method : getMethods()) { if (httpMethod.matches(method.name())) { return new RequestMethodsRequestCondition(method); } } if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) { return GET_CONDITION; } } return null; }