Guest User

Untitled

a guest
Jun 25th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <cffunction name="allowCrossDomainAccess" returnType="void" access="public">
  2.  
  3. <cfset var stHeaders = getHttpRequestData().headers />
  4.  
  5. <cfif structKeyExists( stHeaders, "Origin" ) and cgi.request_method eq "OPTIONS">
  6.  
  7. <!---
  8. Preflighted requests:
  9. 1. browser tells us it wants to make a non-basic x-domain request. Non-basic could mean it is a PUT, or contains custom headers, or a different content-type
  10. 2. based on what the browser tells us it wants to do, we respond and tell it what x-domain requests we allow
  11. --->
  12. <!--- x-domain requests from this host are allowed: * = any host allowed --->
  13. <cfheader name="Access-Control-Allow-Origin" value="*" />
  14. <!--- which http methods are allowed --->
  15. <cfheader name="Access-Control-Allow-Methods" value="GET, POST, ACCEPT, OPTIONS" />
  16. <!--- which custom headers are allowed --->
  17. <cfheader name="Access-Control-Allow-Headers" value="X-Something-Custom, X-Something-Else" />
  18. <!--- the value in seconds for how long the response to the preflight request can be cached for without sending another preflight request. 1728000 seconds is 20 days --->
  19. <cfheader name="Access-Control-Max-Age" value="1728000" />
  20. <!--- allow cookies? NB: when enabled, wildcard Access-Control-Allow-Origin is not allowed --->
  21. <!--- <cfheader name="Access-Control-Allow-Credentials" value="true" /> --->
  22.  
  23. <!--- no further messing, just respond with these headers - the browser will cache these 'permissions' and immediately follow-up with the original request --->
  24. <cfcontent type="text/plain" reset="true" />
  25. <cfabort />
  26.  
  27. <cfelseif listFindNoCase("GET,POST", cgi.request_method)>
  28.  
  29. <!---
  30. Simple GET requests:
  31. When the request is GET or POST, and no custom headers are sent, then no preflight check is required.
  32. The browser accepts the response providing we allow it to with the Access-Control-Allow-Origin header
  33. We allow any host to do simple x-domain GET requests
  34. --->
  35. <cfheader name="Access-Control-Allow-Origin" value="*" />
  36.  
  37. </cfif>
  38.  
  39. </cffunction>
Add Comment
Please, Sign In to add comment