Question about create an asynchronous http handler

speedfirst nginx-forum at nginx.us
Mon Jun 20 16:49:46 MSD 2011


Hey, I'm making a custom http handler. The idea is, the user connects to
this handler, and this handler connect to another server to fetch some
information. Therefore the handler itself can't return the http
response. The code framework is as below:

ngx_http_my_custom_handler (ngx_http_request * r) {
     //create a peer connection to another peer
     ...
     ngx_event_peer_connect(peer);
     peer.connection->write->handler = ngx_http_my_send;
     peer.connection->read->handler = ngx_http_my_recv;
     ...
     return ????;
}

ngx_http_my_send {
      //send the request to another peer
}

ngx_http_my_recv {
      //read the response to buffer
      //create response to client
     ngx_http_finalize_request(r, NGX_HTTP_OK);
}

The question is what should I return in "ngx_http_my_custom_handler" to
avoid the request and the connection being disposed? And how to send
back the final response in "ngx_http_my_recv? (is directly using
ngx_http_finalize_request correct?) I check the code of
ngx_http_proxy_module, and it returns NGX_DONE. But it seems not work in
my project. The request is always disposed when NGX_DONE is returned.

Thanks.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,208453,208453#msg-208453




More information about the nginx mailing list