Writing an NGINX module that is depending on subrequest call.
on the callback, I am getting rc=NGX_AGAIN
with request->out=NULL
, of course that mean I cannot get the content of the subrequest response.
In that case what is the expected behavior of the callback ?
Here is the subrequest setup code
/// Setup callback
ngx_http_request_t *sub_request;
ngx_http_post_subrequest_t *callback = ngx_pcalloc(request->pool, sizeof(ngx_http_post_subrequest_t));
callback->handler = callback_proc;
callback->data = data;
ngx_int_t result = ngx_http_subrequest(request, uri, NULL, &sub_request, callback, NGX_HTTP_SUBREQUEST_IN_MEMORY);
The following callback handler would
static ngx_int_t
callback_proc(ngx_http_request_t *request, void *data, ngx_int_t rc) {
// unbox and sanity check
data->value->len = r->out->buf->last - r->out->buf->pos; // <<-- SIGSEV because r->out is NULL
data->value->data = r->out->buf->pos;
return rc;
}
My issue was that my module handler were intercepting the response and were waiting for the subrequest to complete, and while waiting for the subrequest issued the
NGX_AGAIN
.In your handler be sure to redirect to proper care for redirect your subrequest if they happen to handle the same type of content.
Meaning would have to test for
request->parent
which Should beNULL
if main request.