Welcome! Log In Create A New Profile

Advanced

Question about create an asynchronous http handler

June 20, 2011 08:49AM
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.
Subject Author Posted

Question about create an asynchronous http handler

speedfirst June 20, 2011 08:49AM

Re: Question about create an asynchronous http handler

speedfirst June 20, 2011 09:21AM

Re: Question about create an asynchronous http handler

Maxim Dounin June 20, 2011 10:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 192
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready