httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Lewis <...@joe-lewis.com>
Subject Re: Intercepting HTTP 301/302 redirects
Date Thu, 01 Mar 2012 16:41:20 GMT
Congrats!  Welcome to the world of filters!


On 03/01/2012 09:37 AM, Swaminathan Bhaskar wrote:
> Ahh - Finally, I was able to get it working. Thanks for the pointer.
>
> Here is the code snippet:
>
> #include<stdio.h>
> #include<httpd.h>
> #include<http_protocol.h>
> #include<http_config.h>
> #include<http_log.h>
> #include<util_filter.h>
>
> #define MY_FILTER_NAME "myfilter"
>
> static void insert_myfilter(request_rec *req)
> {
>      ap_add_output_filter(MY_FILTER_NAME, NULL, req, req->connection);
>
>      ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, req->server, "mod_myfilter:
> inserted myfilter");
> }
>
> static int my_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
> {
>      if (f->r->status_line != NULL) {
>          ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, f->r->server,
> "mod_myfilter: status = %d, status-line = %s", f->r->status,
> f->r->status_line);
>      }
>      else {
>          ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, f->r->server,
> "mod_myfilter: status = %d", f->r->status);
>      }
>
>      ap_pass_brigade(f->next, bb);
>
>      return APR_SUCCESS;
> }
>
> static void my_filter_hooks(apr_pool_t *pool)
> {
>      ap_register_output_filter(MY_FILTER_NAME, my_output_filter, NULL,
> AP_FTYPE_RESOURCE);
>
>      ap_hook_insert_filter(insert_myfilter, NULL, NULL, APR_HOOK_LAST);
>
>      ap_hook_insert_error_filter(insert_myfilter, NULL, NULL, APR_HOOK_LAST);
>
>      fprintf(stderr, "mod_myfilter: registered my_output_filter\n");
> }
>
> module AP_MODULE_DECLARE_DATA myfilter_module = {
>      STANDARD20_MODULE_STUFF,
>      NULL,
>      NULL,
>      NULL,
>      NULL,
>      NULL,
>      my_filter_hooks
> };
>
> Rgds
> Bhaskar

Mime
View raw message