Java Code Examples for org.springframework.http.HttpMethod#matches()

The following examples show how to use org.springframework.http.HttpMethod#matches() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Check the HTTP request method (or the method from the
 * {@code Access-Control-Request-Method} header on a pre-flight request)
 * against the configured allowed methods.
 * @param requestMethod the HTTP request method to check
 * @return the list of HTTP methods to list in the response of a pre-flight
 * request, or {@code null} if the supplied {@code requestMethod} is not allowed
 */
public List<HttpMethod> checkHttpMethod(HttpMethod requestMethod) {
	if (requestMethod == null) {
		return null;
	}
	List<String> allowedMethods =
			(this.allowedMethods != null ? this.allowedMethods : new ArrayList<String>());
	if (allowedMethods.contains(ALL)) {
		return Collections.singletonList(requestMethod);
	}
	if (allowedMethods.isEmpty()) {
		allowedMethods.add(HttpMethod.GET.name());
	}
	List<HttpMethod> result = new ArrayList<HttpMethod>(allowedMethods.size());
	boolean allowed = false;
	for (String method : allowedMethods) {
		if (requestMethod.matches(method)) {
			allowed = true;
		}
		HttpMethod resolved = HttpMethod.resolve(method);
		if (resolved != null) {
			result.add(resolved);
		}
	}
	return (allowed ? result : null);
}
 
Example 2
@Nullable
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
	HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
	if (httpMethod != null) {
		for (RequestMethod method : getMethods()) {
			if (httpMethod.matches(method.name())) {
				return requestMethodConditionCache.get(method.name());
			}
		}
		if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
			return requestMethodConditionCache.get(HttpMethod.GET.name());
		}
	}
	return null;
}
 
Example 3
@Nullable
private RequestMethodsRequestCondition matchRequestMethod(@Nullable HttpMethod httpMethod) {
	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;
}
 
Example 4
@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;
}
 
Example 5
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;
}