
bobtfish at bobtfish
Dec 7, 2011, 1:39 AM
Post #2 of 2
(236 views)
Permalink
|
On 7 Dec 2011, at 07:32, Denis Spichkin wrote: > chunked response and Catalyst ?? Totally possible. > Is there any way of generating chunked response inside Catalyst and > any its Views. > The default way that the views / RenderView extension works is to render an entire page and give that to the user, as that's simplest. > I have inside side that create chunked response , created gradually > output for example such as > You can setup your headers, then call ->render on your view to render a chunk, and call $c->write to write chunks out in a loop - this will work just fine :) Doing a multipart streaming response to javascript code (using DUI.Stream or whatever on the client side) would work something like this: my $boundary = MIME::Base64::encode(join("", map chr(rand(256)), 1..$size*3), ""); $boundary =~ s/[\W]/X/g; # ensure alnum only $c->res->header("Content-Type" => 'multipart/mixed; boundary="' . $boundary . '"'); $c->res->body(''); $c->write("--" . $boundary . "\n"); while (my $thing = $iter->next) { $c->stash(item => $thing); my $payload = $c->view('JSON')->render; $c->write("Content-Type: application/json\n\n$payload\n--" . $boundary. "\n" ); } > > I have inside side that create chunked response , created gradually > output for example such as > http://www.websitepulse.com/help/testreq.php?host=www.ya.ru&location=9&type=1&singletestpage=ping-test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&__=1323068838832 > I note that the example you've given here _is not_ doing a chunked response. 'Chunked' implies RFC 2405/2406 MIME chunking, whereas the above serves a plain HTML page and just flushes it to the browser in parts (much simpler, but both less powerful). More analogous code would be something like: for (1..10) { $c->write('response part ' . $_); sleep 1; } > I need create Catalyst Controller that after getting client request > will generate request to my inside resource and get chunked response > and while getting chunked response will generate through any Catalyst > View chunked response to first client request. > I'm not quite sure what you're after here, or if what I've suggested above solves it - please feel free to ask for more details :) Cheers t0m _______________________________________________ List: Catalyst [at] lists Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst [at] lists/ Dev site: http://dev.catalyst.perl.org/
|