Hi all,<div><br></div><div>Finally, I do not use subrequest, I write the following code, inspired from upstream module.</div><div>I call ngx_http_upstream_send_another_request from process_header. It's working fine.</div>
<div><br></div><div>Feel free to comment my code, if you think I can have problem, memory allocation, segfault or others.</div><div><br></div><div>Regards,</div><div><br></div><div>Bertrand<br><div><br></div><div><div><br>
</div><div>static void</div><div>ngx_http_upstream_send_another_request_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u)</div><div>{</div><div>    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,</div>
<div>                   "http upstream send another request dummy handler");</div><div>}</div><div><br></div><div>static ngx_int_t</div><div>ngx_http_upstream_send_another_request(ngx_http_request_t *r, ngx_http_upstream_t *u);</div>
<div>  </div><div>static void</div><div>ngx_http_upstream_send_another_request_handler(ngx_http_request_t *r, ngx_http_upstream_t *u)</div><div>{</div><div>    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,</div>
<div>                   "http upstream send another request handler");</div><div>                   </div><div>    ngx_http_upstream_send_another_request(r, u);</div><div>}</div><div><br></div><div>static ngx_int_t</div>
<div>ngx_http_upstream_send_another_request(ngx_http_request_t *r, ngx_http_upstream_t *u)</div><div>{</div><div>    ngx_int_t          rc;</div><div>    ngx_connection_t  *c;</div><div><br></div><div>    c = u->peer.connection;</div>
<div><br></div><div>    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,</div><div>                   "http upstream send another request");</div><div>    // </div><div>    // if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {</div>
<div>    //     ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);</div><div>    //     return;</div><div>    // }</div><div><br></div><div>    c->log->action = "sending request to upstream";</div><div>
<br></div><div>    rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs);</div><div><br></div><div>    u->request_sent = 1;</div><div><br></div><div>    if (rc == NGX_ERROR) {</div><div>
        return rc;</div><div>    }</div><div><br></div><div>    if (c->write->timer_set) {</div><div>        ngx_del_timer(c->write);</div><div>    }</div><div><br></div><div>    if (rc == NGX_AGAIN) {</div><div>
       ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,</div><div>                       "ngx_output_chain return NGX_AGAIN");</div><div>        </div><div>        u->write_event_handler = ngx_http_upstream_send_another_request_handler;</div>
<div>        </div><div>        ngx_add_timer(c->write, u->conf->send_timeout);</div><div><br></div><div>        if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) {</div><div>          return NGX_ERROR;</div>
<div>        }</div><div><br></div><div>        return NGX_AGAIN;</div><div>    }</div><div><br></div><div>    /* rc == NGX_OK */</div><div><br></div><div>    if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {</div><div>        if (ngx_tcp_push(c->fd) == NGX_ERROR) {</div>
<div>            ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,</div><div>                          ngx_tcp_push_n " failed");</div><div>            return NGX_ERROR;</div><div>        }</div><div><br>
</div><div>        c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;</div><div>    }</div><div><br></div><div>    ngx_add_timer(c->read, u->conf->read_timeout);</div><div><br></div><div>// #if 1</div><div>//     if (c->read->ready) {</div>
<div>// </div><div>//         /* post aio operation */</div><div>// </div><div>//         /*</div><div>//          * TODO comment</div><div>//          * although we can post aio operation just in the end</div><div>//          * of ngx_http_upstream_connect() CHECK IT !!!</div>
<div>//          * it's better to do here because we postpone header buffer allocation</div><div>//          */</div><div>// </div><div>//          return u->process_header(r);</div><div>//     }</div><div>// #endif</div>
<div><br></div><div>    u->write_event_handler = ngx_http_upstream_send_another_request_dummy_handler;</div><div><br></div><div>    if (ngx_handle_write_event(c->write, 0) != NGX_OK) {</div><div>        return NGX_ERROR;</div>
<div>    }</div><div>    </div><div>    return NGX_AGAIN;</div><div>}</div><br><div class="gmail_quote">On Tue, Jan 17, 2012 at 04:14, bigplum <span dir="ltr"><<a href="mailto:nginx-forum@nginx.us">nginx-forum@nginx.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
This demo maybe helpful.<br>
<a href="https://github.com/bigplum/nginx-http-nphase-module" target="_blank">https://github.com/bigplum/nginx-http-nphase-module</a><br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,221329,221339#msg-221339" target="_blank">http://forum.nginx.org/read.php?2,221329,221339#msg-221339</a><br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br></div></div>