Every new module-implementor should look at this example: http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/examples/mod_example_hooks.c
Although I'm not particularly proud of how complicated our apache-gasket has gotten -- it could use a refactor or 5, this is mod_pagespeed's output filter registration call: http://code.google.com/p/modpagespeed/source/browse/trunk/src/net/instaweb/apache/mod_instaweb.cc#753 Also see instaweb_out_filter and process_bucket in the same file. -Josh On Fri, Jan 13, 2012 at 2:10 PM, Pranesh Vadhirajan < vadhira...@teralogics.com> wrote: > Hello,**** > > I’ve been trying to use output filters in my code in order to read the > response that is being sent from Apache to a web client. **** > > ** ** > > I believe this would be a proper use for an output filter, please correct > me if I’m wrong. I am attempting to read the content of the response from > within a certain module, and I would like to know how to access the > contents of the output filter etc. **** > > ** ** > > I’ve been looking into how output filters work, but I’m not sure I > understand the concept. **** > > ** ** > > So here are my basic questions on how to write that code:**** > > ** ** > > Can I register my output filter within the registration hooks of my module > code? For example I did the following and I am getting various errors, and > I am wondering if there’s a proper way to do it. The goal is to be able to > access the contents of the response from within my module and to print it > to my error log (or anywhere else), but I am not sure how to do this. : ** > ** > > ** ** > > static apr_status_t apcontent_filter_in(ap_filter_t *f, apr_bucket_brigade > *b, ap_input_mode_t mode, apr_size_t *readbytes)**** > > {**** > > const char *str;**** > > int length;**** > > apr_bucket *e;**** > > ** ** > > ap_get_brigade(f->next, b, mode, APR_BLOCK_READ,1);**** > > ** ** > > e = APR_BRIGADE_FIRST(b);**** > > ** ** > > if (e->type == NULL) {**** > > return APR_SUCCESS;**** > > }**** > > ** ** > > apr_bucket_read(e, &str, &length, 1);**** > > fprintf(stderr,"req body: %s\n",str);**** > > ** ** > > return APR_SUCCESS;**** > > }**** > > ** ** > > static int my_handler(request_rec* r) {**** > > ** ** > > int is_ip = 0, fqdn_id, ap_id, nid_sl = 0, nid_fl = 0;**** > > char time_buffer[30]; **** > > char* remote_address;**** > > char* cookie;**** > > char* session_id = NULL;**** > > ** ** > > apr_bucket_brigade* request_body_brigade;**** > > ap_filter_t *f;**** > > apr_size_t readbytes=(apr_size_t)r->sent_bodyct;**** > > > apcontent_filter_in(f,request_body_brigade,AP_MODE_READBYTES,&readbytes);* > *** > > ** ** > > return DECLINED;**** > > ** ** > > }**** > > ** ** > > static void my_register_hooks (apr_pool_t *p) {**** > > ap_hook_handler(my_handler, NULL, NULL, APR_HOOK_MIDDLE);**** > > ap_register_input_filter("get_request_body", > apcontent_filter_in,NULL, AP_FTYPE_RESOURCE) ;**** > > }**** > > ** ** > > module AP_MODULE_DECLARE_DATA my_module = **** > > {**** > > STANDARD20_MODULE_STUFF,^M**** > > NULL, /* Per-Directory > Configuration */**** > > NULL, /* Directory > Config Merger */**** > > NULL, /* Per-Server > Configuration */**** > > NULL, /* Server Config > Merger */**** > > NULL, /* Command Table > (Directives) */**** > > my_register_hooks /* Registering Hooks */**** > > };**** > > ** ** > > If this is not the proper way to read from an output filter could someone > please explain the proper way?**** > > ** ** > > Thanks, > Pranesh Vadhirajan**** > > ** ** > > ** ** >