Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active January 21, 2021 22:17
Show Gist options
  • Save JamoCA/575182d2b2378ad57334e080d9a31209 to your computer and use it in GitHub Desktop.
Save JamoCA/575182d2b2378ad57334e080d9a31209 to your computer and use it in GitHub Desktop.
ColdFusion / CFML UDF to determine if request/content has been flushed using CFFlush or by exceeding max buffer.
<cfscript>
/* 20200121 ColdFusion / CFML UDF to determine if request/content has been flushed using CFFlush or by exceeding max buffer. */
boolean function isFlushed(){
var response = false;
var headers = {};
if (StructKeyExists(request, "isFlushedAlready") AND isValid("boolean", request.isFlushedAlready) and request.isFlushedAlready){
return true;
}
headers = GetHttpRequestData(false).headers;
if (StructKeyExists(headers, "Expect") or not len(CGI.HTTP_Connection)){
response = true;
} else if (StructKeyExists(Server, "lucee")){
response = getPageContext().getHttpServletResponse().isCommitted() or getPageContext().getHttpServletResponse().isTreatAsCommitted();
} else {
response = getPageContext().getResponse().isCommitted() or getPageContext().getFusionContext().getResponse().isOutputAutoFlushed();
}
request.isFlushedAlready = response;
return response;
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment