ngx_http_catch_body_filter doesn't appear to work

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view

ngx_http_catch_body_filter doesn't appear to work

I'm trying to use the ngx_http_catch_body_filter example to capture request
bodies from post (etc.) requests.  

I started with the example here in the hg repo:

I changed the config to make it a dynamic nginx module.

I can see the `ngx_http_catch_body_init()`  method getting called in the
logs (I put an error log in that method).

When I try a proxied POST or file upload, `ngx_http_catch_body_filter()`
never gets called.

Here's my modified source code and config.   What am I doing wrong?

---- nginx.conf ----
load_module modules/;
        location /app1/ {
            catch_body on;
            proxy_pass http://localhost:8180/java_test_app/;


---- config ----
# (C) Maxim Dounin
# Configuration for ngx_http_catch_body_filter_module.


# ngx_http_catch_body_filter_module"



. auto/module

---- ngx_http_catch_body_filter_module.c ----

 * Copyright (C) Maxim Dounin

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <stddef.h>

typedef struct {
    ngx_flag_t enable;
} ngx_http_catch_body_conf_t;

static void *ngx_http_catch_body_create_conf(ngx_conf_t *cf);

static char *ngx_http_catch_body_merge_conf(ngx_conf_t *cf, void *parent,
                                            void *child);

static ngx_int_t ngx_http_catch_body_init(ngx_conf_t *cf);

static ngx_command_t ngx_http_catch_body_commands[] = {

         offsetof(ngx_http_catch_body_conf_t, enable),


static ngx_http_module_t ngx_http_catch_body_module_ctx = {
        NULL,                          /* preconfiguration */
        ngx_http_catch_body_init,      /* postconfiguration */

        NULL,                          /* create main configuration */
        NULL,                          /* init main configuration */

        NULL,                          /* create server configuration */
        NULL,                          /* merge server configuration */

        ngx_http_catch_body_create_conf, /* create location configuration
        ngx_http_catch_body_merge_conf   /* merge location configuration */

ngx_module_t ngx_http_catch_body_filter_module = {
        &ngx_http_catch_body_module_ctx, /* module context */
        ngx_http_catch_body_commands,  /* module directives */
        NGX_HTTP_MODULE,               /* module type */
        NULL,                          /* init master */
        NULL,                          /* init module */
        NULL,                          /* init process */
        NULL,                          /* init thread */
        NULL,                          /* exit thread */
        NULL,                          /* exit process */
        NULL,                          /* exit master */

static ngx_http_request_body_filter_pt ngx_http_next_request_body_filter;

static ngx_int_t
ngx_http_catch_body_filter(ngx_http_request_t *r, ngx_chain_t *in) {
    ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, "catch request body
    fprintf(stderr, "catch request body filter\n");
    return ngx_http_next_request_body_filter(r, in);

static void *
ngx_http_catch_body_create_conf(ngx_conf_t *cf) {
    ngx_http_catch_body_conf_t *conf;

    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_catch_body_conf_t));
    if (conf == NULL) {
        return NULL;

    conf->enable = NGX_CONF_UNSET;
    return conf;

static char *
ngx_http_catch_body_merge_conf(ngx_conf_t *cf, void *parent, void *child) {
    ngx_http_catch_body_conf_t *prev = parent;
    ngx_http_catch_body_conf_t *conf = child;

    ngx_conf_merge_value(conf->enable, prev->enable, 0);
    return NGX_CONF_OK;

static ngx_int_t
ngx_http_catch_body_init(ngx_conf_t *cf) {
    ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "init catch request body
    ngx_http_next_request_body_filter = ngx_http_top_request_body_filter;
    ngx_http_top_request_body_filter = ngx_http_catch_body_filter;
    return NGX_OK;

Posted at Nginx Forum:,285923,285923#msg-285923

nginx mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: ngx_http_catch_body_filter doesn't appear to work

Please disregard or delete this post.  The problem was with my setup.  It
works fine.  Thanks.

Posted at Nginx Forum:,285923,285941#msg-285941

nginx mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: ngx_http_catch_body_filter doesn't appear to work

In reply to this post by vergil
i still have the same issue, could you assist me please,

Thank you in advance

Posted at Nginx Forum:,285923,288678#msg-288678

nginx mailing list
[hidden email]