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!