Skip to content

Instantly share code, notes, and snippets.

@JamoCA JamoCA/NewLocation.cfm
Last active May 18, 2017

What would you like to do?
CF_NewLocation - Duplicate of built-in ColdFusion CFLocation function but with added ability to prevent penalty when using rate limiter
<!--- 5/18/2017 NewLocation Check and reduce Optional rate-limiter prior to redirect
Rate Limiter UDF that uses CFCache:
Use just like tag-based CFLocation tag
<CF_NewLocation url="http://localhost:8500/cfdocs/dochome.htm" addToken="no"> --->
<CFPARAM NAME="Attributes.AddToken" DEFAULT="no">
<CFPARAM NAME="Attributes.statusCode" DEFAULT="302">
<CFSET BrowserKey = "#CGI.Server_Name#_#CGI.Remote_Addr#_#CGI.Http_User_Agent#">
<CFSET CurrentLimiter = cacheGet(BrowserKey)>
<CFSET CacheConfig = {}>
<CFIF NOT listFind("300,301,302,303,304,305,307", Attributes.StatusCode)>
<CFSET Attributes.StatusCode = 302>
<CFIF NOT isValid("boolean", Attributes.addToken)>
<CFSET Attributes.addToken = "no">
<CFIF NOT isNull(CurrentLimiter)>
<CFSET CurrentLimiter.attempts = CurrentLimiter.attempts - 1>
<CFIF CurrentLimiter.attempts LT 1>
<CFSET CurrentLimiter.attempts = 1>
<CFSET CacheConfig = cacheGetMetadata(BrowserKey)>
<CFSET cachePut(browserKey, CurrentLimiter, CreateTimeSpan(0, 0, 0, CacheConfig.timespan))>
<cflocation addtoken="#Attributes.addToken#" statuscode="#Attributes.StatusCode#" url="#Attributes.URL#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.