I’m trying to use Helicon Ape’s mod_xsendfile with Railo server (Windows 2012 R2). mod_xsendfile functions correctly and it works fine with PHP, it deliver the file and also it pass the content length value to the browser too. No file size limit found with PHP and no significant use of sever memory regardless the file size.
With Railo, obvious first attempt.
<cfcontent type="text/plain">
<cfheader name="content-disposition" value="attachment; filename=test.txt"/>
<cfheader name="X-Sendfile" value="D:\iis\hello.txt"/>
This does not work. It returns a blank file; no error log generated by Helicon Ape, so it is safe to assume Header X-Sendfile does not passed into IIS/ correctly.
Second Attempt
<cfheader name="content-disposition" value="attachment; filename=test.txt"/>
<cfset Response = GetPageContext().GetResponse() />
<cfset Response.setHeader('X-Sendfile','D:\iis\hello.txt')>
<cfset Response.setContentType('plain/text')>
<cfset Response.GetOutputStream().Flush() />
<cfset Response.Reset() />
<cfset Response.Finish() />
This works with
Limitation 1: When the file size is more than 2GB, browser returns error “ERR_INVALID_CHUNKED_ENCODING” It works fine with smaller file size, no memory issues. (again, PHP seems not to have this issue. IIS do not have a size limit either)
Limitation 2: This does not pass the content-length to the browser, hence browser don’t know the size of the file.
Third Attempt: Add content-length manually. (this is not necessary with PHP)
<cfset filePath = "D:\iis\246.zip">
<cfheader name="content-disposition" value="attachment; filename=246.zip"/>
<cfset Response = GetPageContext().GetResponse() />
<cfset Response.setContentLength( createObject("java","java.io.File").init( filePath ).length() )>
<cfset Response.setHeader('X-Sendfile', filePath )>
<cfset Response.setContentType('application/octet-stream')>
<cfset Response.GetOutputStream().Flush() />
<cfset Response.Reset() />
<cfset Response.Finish() />
Content-length passed into the browser, but unlike with PHP, IIS tries to allocate memory for the file and it soon end up with “Overflow or underflow in the arithmetic operation” error.
I’m sure I’m not handling GetPageContext().GetResponse() correctly. If anyone can help me out here, I would be highly appreciated.