Problems Directly printing to Apache2::RequestRec buffer with dancer
I'm retrofitting Dancer onto an existing perl application of mine. However, some of the code, for large report generations, will directly print to the web buffer. This is resulting in nothing come back in my response. E.g, with this route handler: get '/buffertest' => sub { my $r = request->input_handle; $r->print("hello world"); # ref $r == Apache2::RequestRec return; }; And then I make a request to it... ==== Begin Request Dump ==== GET http://localhost/buffertest Content-Type: application/json === End Request Dump ==== ... , the response won't come back: ==== Begin Response Dump ==== HTTP/1.1 200 OK Connection: close Date: Wed, 30 Apr 2014 16:37:19 GMT Server: Apache Vary: Accept-Encoding,User-Agent Content-Length: 0 Content-Type: text/html; charset=utf-8 Client-Date: Wed, 30 Apr 2014 16:37:20 GMT Client-Peer: 10.5.15.5:80 Client-Response-Num: 1 P3P: CP="CAO PSA OUR" === End Response Dump ==== IF however, I do something like enable autoflushing ($|=1) then I will get "hello world" back, but that feels like a very brutal hack. Is there an equivalent way to flush response in Dancer?
On April 30, 2014 11:24:32 AM Brian Brandes wrote:
get '/buffertest' => sub { my $r = request->input_handle; $r->print("hello world"); # ref $r == Apache2::RequestRec return; };
If all you are doing with the $r object is printing, maybe a little wrapper could do the trick: sub capture_output(&) { open my $handle, '>', \my $output; $_[0]->($handle); return $output; } get '/' => sub { return capture_output { my $r = shift; $r->print( "hello there!"); } }; Joy, `/anick
participants (2)
-
Brian Brandes -
Yanick Champoux