Hi Monks,

I am using AnyEvent::HTTPD / AnyEvent::HTTP::Request. I want to be able to do async IO when a request comes in, and have ability to set the response status, and response content-type, based on the result of that async IO.

However I cannot figure out any way to do this. All the examples I have see all require the content-type specified up-front - and their behavior is that the client is immediately sent response headers (with 200 status and content-type), and then async IO callback is provided, such that only the response body can be asynchronously generated. Example based on AnyEvent::HTTPD::Request doc:

$req->respond ({ content => ['text/plain', sub { my ($data_cb) = @_; # 200 / text/plain already sent to client by now... # do async io that eventually calls the call back... myPromise()->then(sub{ $data_cb->("OK"); # Too late to change content-type or status co +de here.. $data_cb->(); })->catch(sub{ $data_cb->("Failed"); # Or here... $data_cb->(); }); } });

Any ideas? Or should I change to a different 'framework'? Thanks!


In reply to AnyEvent::HTTPD::Request Dynamic Async Response by sectokia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.