query_reviewer icon indicating copy to clipboard operation
query_reviewer copied to clipboard

QR causes Rails' send_file to send 0kb files

Open jdelStrother opened this issue 13 years ago • 0 comments

Hi, If query_reviewer is enabled, it has the 'interesting' side effect of making send_file send 0kb files. This is due to calling 'response.body' in add_query_output_to_view, which then reads the entire File object into a string in ActionDispatch::Response#each, meaning that when Rack tries to return the file, it's already read to the end and just returns an empty string.

Before calling response.body, we might fetch the response ivar @body and check that it's not a file, or check the headers to see they include sendfile stuff. Or we could rewind the file, assuming you can figure out that it was a file in the first place. None of those options sound very appealing.

I'm not sure there's a good solution to this, but it took a really long time to track down and I thought I'd mention it for future googlers.

jdelStrother avatar Aug 11 '11 15:08 jdelStrother