当前位置: 首页>>代码示例>>Java>>正文


Java CorsUtils.isPreFlightRequest方法代码示例

本文整理汇总了Java中org.springframework.web.cors.CorsUtils.isPreFlightRequest方法的典型用法代码示例。如果您正苦于以下问题:Java CorsUtils.isPreFlightRequest方法的具体用法?Java CorsUtils.isPreFlightRequest怎么用?Java CorsUtils.isPreFlightRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.cors.CorsUtils的用法示例。


在下文中一共展示了CorsUtils.isPreFlightRequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilterInternal

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    if (corsEnabled) {
        if (CorsUtils.isCorsRequest(request)) {
            response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, defaultIfBlank(request.getHeader(ORIGIN), "*"));
            response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, defaultIfBlank(request.getHeader(ACCESS_CONTROL_REQUEST_METHOD),
                    "HEAD, POST, PUT, GET, OPTIONS, DELETE"));
            response.setHeader(ACCESS_CONTROL_ALLOW_HEADERS, defaultIfBlank(request.getHeader(ACCESS_CONTROL_REQUEST_HEADERS),
                    join(new String[]{CONTENT_TYPE, ACCEPT}, ',')));
            response.setHeader(ACCESS_CONTROL_EXPOSE_HEADERS, LOCATION);
            response.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
            response.setHeader(ACCESS_CONTROL_MAX_AGE, "3601");
        }

        if (!CorsUtils.isPreFlightRequest(request)) {
            filterChain.doFilter(request, response);
        }
    } else {
        super.doFilterInternal(request, response, filterChain);
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:22,代码来源:CorsFilter.java

示例2: doOptions

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper for Servlet 2.5 compatibility where
	// the getHeader() method does not exist
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + RequestMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:FrameworkServlet.java

示例3: incomingRequestPreProcessed

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
@Override
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
	if (CorsUtils.isCorsRequest(theRequest)) {
		boolean isValid;
		try {
			isValid = myCorsProcessor.processRequest(myConfig, theRequest, theResponse);
		} catch (IOException e) {
			throw new InternalErrorException(e);
		}
		if (!isValid || CorsUtils.isPreFlightRequest(theRequest)) {
			return false;
		}
	}

	return super.incomingRequestPreProcessed(theRequest, theResponse);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:17,代码来源:CorsInterceptor.java

示例4: getMatchingCondition

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
/**
 * Checks if all conditions in this request mapping info match the provided request and returns
 * a potentially new request mapping info with conditions tailored to the current request.
 * <p>For example the returned instance may contain the subset of URL patterns that match to
 * the current request, sorted with best matching patterns on top.
 * @return a new instance in case all conditions match; or {@code null} otherwise
 */
@Override
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
	RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
	ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
	HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
	ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
	ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);

	if (methods == null || params == null || headers == null || consumes == null || produces == null) {
		if (CorsUtils.isPreFlightRequest(request)) {
			methods = getAccessControlRequestMethodCondition(request);
			if (methods == null || params == null) {
				return null;
			}
		}
		else {
			return null;
		}
	}

	PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
	if (patterns == null) {
		return null;
	}

	RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
	if (custom == null) {
		return null;
	}

	return new RequestMappingInfo(this.name, patterns,
			methods, params, headers, consumes, produces, custom.getCondition());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:41,代码来源:RequestMappingInfo.java

示例5: lookupHandlerMethod

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
/**
 * Look up the best-matching handler method for the current request.
 * If multiple matches are found, the best match is selected.
 * @param lookupPath mapping lookup path within the current servlet mapping
 * @param request the current request
 * @return the best-matching handler method, or {@code null} if no match
 * @see #handleMatch(Object, String, HttpServletRequest)
 * @see #handleNoMatch(Set, String, HttpServletRequest)
 */
protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception {
	List<Match> matches = new ArrayList<Match>();
	List<T> directPathMatches = this.mappingRegistry.getMappingsByUrl(lookupPath);
	if (directPathMatches != null) {
		addMatchingMappings(directPathMatches, matches, request);
	}
	if (matches.isEmpty()) {
		// No choice but to go through all mappings...
		addMatchingMappings(this.mappingRegistry.getMappings().keySet(), matches, request);
	}

	if (!matches.isEmpty()) {
		Comparator<Match> comparator = new MatchComparator(getMappingComparator(request));
		Collections.sort(matches, comparator);
		if (logger.isTraceEnabled()) {
			logger.trace("Found " + matches.size() + " matching mapping(s) for [" +
					lookupPath + "] : " + matches);
		}
		Match bestMatch = matches.get(0);
		if (matches.size() > 1) {
			if (CorsUtils.isPreFlightRequest(request)) {
				return PREFLIGHT_AMBIGUOUS_MATCH;
			}
			Match secondBestMatch = matches.get(1);
			if (comparator.compare(bestMatch, secondBestMatch) == 0) {
				Method m1 = bestMatch.handlerMethod.getMethod();
				Method m2 = secondBestMatch.handlerMethod.getMethod();
				throw new IllegalStateException("Ambiguous handler methods mapped for HTTP path '" +
						request.getRequestURL() + "': {" + m1 + ", " + m2 + "}");
			}
		}
		handleMatch(bestMatch.mapping, lookupPath, request);
		return bestMatch.handlerMethod;
	}
	else {
		return handleNoMatch(this.mappingRegistry.getMappings().keySet(), lookupPath, request);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:48,代码来源:AbstractHandlerMethodMapping.java

示例6: doFilterInternal

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
		FilterChain filterChain) throws ServletException, IOException {

	if (CorsUtils.isCorsRequest(request)) {
		CorsConfiguration corsConfiguration = this.configSource.getCorsConfiguration(request);
		if (corsConfiguration != null) {
			boolean isValid = this.processor.processRequest(corsConfiguration, request, response);
			if (!isValid || CorsUtils.isPreFlightRequest(request)) {
				return;
			}
		}
	}
	filterChain.doFilter(request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:CorsFilter.java

示例7: getMatchingCondition

import org.springframework.web.cors.CorsUtils; //导入方法依赖的package包/类
/**
 * Returns "this" instance if the request matches all expressions; or {@code null} otherwise.
 */
@Override
public ServerNameRequestCondition getMatchingCondition(HttpServletRequest request) {
	// logger.info("getMatchingCondition:" + request.getRequestURI());
	if (CorsUtils.isPreFlightRequest(request)) {
		return PRE_FLIGHT_MATCH;
	}
	for (HeaderExpression expression : expressions) {
		if (!expression.match(request)) {
			return null;
		}
	}
	return this;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:17,代码来源:ServerNameRequestCondition.java


注:本文中的org.springframework.web.cors.CorsUtils.isPreFlightRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。