Thanks for the tips, but I think I have a more basic gap in the understanding.
I'm adding here the only change I've made - the new ngx_http_lua_capture_body_filter. The that were changed are marked by "/*~~~*/".
The phenomena that happens is that when trying to download a file of 2MB, only 3 chunks of 32768 bytes are returned (96KB all in all).
static ngx_int_t
ngx_http_lua_capture_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
/* int rc; */
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_ctx_t *pr_ctx;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua capture body filter, uri \"%V\"", &r->uri);
if (in == NULL) {
return ngx_http_lua_next_body_filter(r, NULL);
}
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (!ctx || !ctx->capture) {
dd("no ctx or no capture %.*s", (int) r->uri.len, r->uri.data);
return ngx_http_lua_next_body_filter(r, in);
}
if (ctx->run_post_subrequest) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua body filter skipped because post subrequest "
"already run");
return NGX_OK;
}
if (r->parent == NULL) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua body filter skipped because no parent request "
"found");
return NGX_ERROR;
}
pr_ctx = ngx_http_get_module_ctx(r->parent, ngx_http_lua_module);
if (pr_ctx == NULL) {
return NGX_ERROR;
}
/*~~~*/
rc = ngx_http_lua_send_chain_link(r->parent, pr_ctx, in);
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "~~~ Failed sending...");
return NGX_ERROR;
}
return NGX_OK;
/*~~~*/
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua capture body filter capturing response body, uri "
"\"%V\"", &r->uri);
rc = ngx_http_lua_add_copy_chain(r, pr_ctx, &ctx->last_body, in);
if (rc != NGX_OK) {
return NGX_ERROR;
}
ngx_http_lua_discard_bufs(r->pool, in);
return NGX_OK;
}
On Tuesday, March 19, 2013 9:23:43 PM UTC+2, agentzh wrote:
Hello!
On Tue, Mar 19, 2013 at 10:18 AM, aviram wrote:
> I've been using ngx_http_lua_send_chain_link in a body filter (written in C
> - that is the capture filter of the Lua module) in order to send chain data
> back straight to the user.
> For some reason, the data is trimmed - for a file with a size of 2MB, only
> 100KB are actually downloaded.
>
> The response doesn't contain a Content-Length field, but an ASCII zero ("0")
> is sent during the response (but prior to its last buffer).
>
Because you're coding in C right now, it is very likely that you're
having buffer management issues (or memory issues in general) here :)
Try running your code with the Valgrind's memcheck tool to see if
there's something going on. Also, systemtap is a great tool to trace
the status of chain links in various levels of output filters (even
down to the level of the writev syscall).
Since you do not provide your code, I cannot get you any further.
Best regards,
-agentzh