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; } 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; }
static ngx_int_t ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { int rc; ngx_http_lua_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module); if(!ctx || !ctx->capture) { return ngx_http_lua_next_body_filter(r, in); } rc = ngx_http_lua_add_copy_chain(r->pool, &ctx->body, in); if (rc != NGX_OK) { return NGX_ERROR; } ngx_http_lua_discard_bufs(r->pool, in); return NGX_OK; }