httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bogdan Ribic <>
Subject I need a working example of connection-level input filter
Date Thu, 01 Feb 2007 01:37:08 GMT
Hi all,

  I'm having lots of fun with connection-level input filter. Idea is to modify headers before
apache starts processing them. I adapted example from mod_case_filter_in and it all works
until I try to use it with AP_FTYPE_CONNECTION. Specifically, this piece of code:

    while (!APR_BRIGADE_EMPTY(ctx->bb)) {
        apr_bucket * bkt_in = APR_BRIGADE_FIRST(ctx->bb);

will set bkt_in to NULL even though bucket is not empty, and it will only do so when filter
is registered as AP_FTYPE_CONNECTION. If it is AP_FTYPE_RESOURCE it works as expected.

  So, I guess I need a very simple example where it all works.

  Whole filter function is adapted from example in case_filter, and looks like this:

apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
    ap_input_mode_t mode, apr_read_type_e block, apr_off_t nbytes)
    int size;
    const char * str;
    apr_status_t rv;
    hpfilter_ctx_t * ctx = NULL;
    request_rec *r = f->r;
    conn_rec *c = r->connection;
    if (!(ctx = f->ctx == NULL)) {
        f->ctx = ctx = apr_pcalloc(r->pool, sizeof *ctx);
        ctx->bb = apr_brigade_create(r->pool, c->bucket_alloc);
    if (APR_BRIGADE_EMPTY(ctx->bb)) {
        rv = ap_get_brigade(f->next, ctx->bb, mode, block, nbytes);

        if (mode == AP_MODE_EATCRLF || rv != APR_SUCCESS)
            return rv;

    while (!APR_BRIGADE_EMPTY(ctx->bb)) {
        apr_bucket * bkt_in = APR_BRIGADE_FIRST(ctx->bb);
        apr_bucket * bkt_out;
        const char * data;
        apr_size_t len;
        char * buf;
        int i;

        if (APR_BUCKET_IS_EOS(bkt_in)) {
            APR_BRIGADE_INSERT_TAIL(bb_out, bkt_in);
        rv = apr_bucket_read(bkt_in, &data, &len, block);
        if (rv != APR_SUCCESS)
            return rv;

        buf = malloc(len);
        for(i = 0; i < len; i++)
            buf[i] = data[i];
        bkt_out = apr_bucket_heap_create(buf, len, 0, c->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(bb_out, bkt_out);
    return rv;

Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.

View raw message