summaryrefslogtreecommitdiffstats
path: root/debian/perl-framework/c-modules/client_add_filter/mod_client_add_filter.c
blob: ce5ef996882f8ad1d430b706a4eb8748c50a0168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define HTTPD_TEST_REQUIRE_APACHE 2

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_log.h"
#include "ap_config.h"

/* 
 * in real life we'd never allow the client to configure filters.
 * the purpose of this module is to let .t tests configure filters
 * this allows to test non-filtered and filtered requests without
 * duplicating lots of test configuration
 */

static int client_add_filter_header(void *data,
                                    const char *key,
                                    const char *val)
{
    request_rec *r = (request_rec *)data;

    if (strcasecmp(key, "X-AddInputFilter") == 0) {
        ap_add_input_filter(val, NULL, r, r->connection);
    }
    else if (strcasecmp(key, "X-AddOutputFilter") == 0) {
        ap_add_output_filter(val, NULL, r, r->connection);
    }

    return 1;
}

static void client_add_filter_insert(request_rec *r)
{
    apr_table_do(client_add_filter_header, (void*)r,
                 r->headers_in, NULL);
}

static void client_add_filter_register_hooks(apr_pool_t *p)
{
    ap_hook_insert_filter(client_add_filter_insert,
                          NULL, NULL, APR_HOOK_LAST);
}

module AP_MODULE_DECLARE_DATA client_add_filter_module = {
    STANDARD20_MODULE_STUFF, 
    NULL,                  /* create per-dir    config structures */
    NULL,                  /* merge  per-dir    config structures */
    NULL,                  /* create per-server config structures */
    NULL,                  /* merge  per-server config structures */
    NULL,                  /* table of config file commands       */
    client_add_filter_register_hooks  /* register hooks          */
};