Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.thetransactioncompany.cors;
 
 
Enumeration of the CORS request types.

Author(s):
Vladimir Dzhuvinov
Brandon Murray
public enum CORSRequestType {


Simple / actual CORS request.
	ACTUAL,


Preflight CORS request.
	PREFLIGHT,


Other (non-CORS) request.
	OTHER;


Detects the CORS type of the specified HTTP request.

Parameters:
request The HTTP request to check. Must not be null.
Returns:
The CORS request type.
	public static CORSRequestType detect(final HttpServletRequest request) {
		if (request.getHeader(.) == null) {
			// All CORS request have an Origin header
			return ;
		}
		// Some browsers include the Origin header even when submitting 
		// from the same domain. This is legal according to RFC 6454, 
		// section-7.3
		String serverOrigin = request.getScheme() + "://" + request.getHeader(.);
		if (request.getHeader(.) != null && request.getHeader(.).equals(serverOrigin)) {
			return ;
		}
		// We have a CORS request - determine type
		    request.getMethod()                                         != null &&
		    request.getMethod().equalsIgnoreCase("OPTIONS")                        ) {
			return ;
else {
			return ;
		}
	}
New to GrepCode? Check out our FAQ X