Last active
May 18, 2017 17:14
-
-
Save JamoCA/09e85bf5a5f5bb3398ae8a8970af6fa7 to your computer and use it in GitHub Desktop.
CF_NewLocation - Duplicate of built-in ColdFusion CFLocation function but with added ability to prevent penalty when using rate limiter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CFSETTING ENABLECFOUTPUTONLY="Yes"> | |
<!--- 5/18/2017 NewLocation Check and reduce Optional rate-limiter prior to redirect | |
Rate Limiter UDF that uses CFCache: https://gist.github.com/JamoCA/f1af7397d92b93eeea20 | |
Use just like tag-based CFLocation tag https://cfdocs.org/cflocation | |
<CF_NewLocation url="http://localhost:8500/cfdocs/dochome.htm" addToken="no"> ---> | |
<CFPARAM NAME="Attributes.URL" DEFAULT="/"> | |
<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> | |
<CFIF NOT isValid("boolean", Attributes.addToken)> | |
<CFSET Attributes.addToken = "no"> | |
</CFIF> | |
<CFIF NOT isNull(CurrentLimiter)> | |
<CFSET CurrentLimiter.attempts = CurrentLimiter.attempts - 1> | |
<CFIF CurrentLimiter.attempts LT 1> | |
<CFSET CurrentLimiter.attempts = 1> | |
</CFIF> | |
<CFSET CacheConfig = cacheGetMetadata(BrowserKey)> | |
<CFSET cachePut(browserKey, CurrentLimiter, CreateTimeSpan(0, 0, 0, CacheConfig.timespan))> | |
</CFIF> | |
<CFSETTING ENABLECFOUTPUTONLY="No"> | |
<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