On Tue, Dec 2, 2008 at 10:58, Ashish Khare <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have tried with this option AP_FTYPE_PROTOCOL.
> But my input filter is not called.
> But when I change the type to AP_FTYPE_RESOURCE, my filter did get called
> but no header.
>
> I have checked the Apache code where following modules filters are
> registered with this option.
>
> ap_register_input_filter("HTTP_IN", ap_http_filter,NULL, AP_FTYPE_PROTOCOL);
> ap_register_input_filter (ssl_io_buffer, ssl_io_filter_buffer, NULL,
> AP_FTYPE_PROTOCOL - 1);
> ap_register_input_filter("NET_TIME", net_time_filter, NULL,
> AP_FTYPE_PROTOCOL);
>
>
> Please find my code snippet below to check if I am doing correct or not.
> Let me know if I am doing correct or not.
Hello,
The apache2 call sequence is:
ap_process_http_connection->ap_read_request->create_request callbacks
->ap_get_mime_headers_core
->ap_process_request->insert_filter callbacks
As you see, ap_get_mime_headers_core is called before the
insert_filter callbacks. Thus, the headers are consumed by
ap_http_filter and they do not reach your filter.
Instead of calling ap_add_input_filter_handle from a insert_filter
callback, call it from a create_request callback. Thus, it will be
called before ap_http_filter.
I've attached the code.
S
>
> code snippet
> ============
>
> module AP_MODULE_DECLARE_DATA input_module = {
> STANDARD20_MODULE_STUFF,
> NULL, /* module initializer */
> NULL, /* create per-dir config structures */
> NULL, /* merge per-dir config structures */
> NULL, /* create per-server config structures */
> my_table, /* merge per-server config structures */
> mod_my_register_hooks,
> };
>
> static ap_filter_rec_t * globalInputFilter;
>
> static void
> mod_my_register_hooks (apr_pool_t * p)
> {
> ap_hook_child_init (my_child_init, NULL, NULL, APR_HOOK_MIDDLE);
> ap_hook_insert_filter(my_insertfilter , NULL, NULL, APR_HOOK_MIDDLE);
> globalInputFilter= ap_register_input_filter("MY_READ_INPUT",
> my_input_filter ,NULL, AP_FTYPE_PROTOCOL );
> };
>
> static void my_insertfilter (request_rec * r)
> {
> ReqRspCtx *ctx;
> ctx = (ReqRspCtx *)apr_palloc(r->pool,sizeof(ReqRspCtx));
> ap_add_input_filter_handle ( globalInputFilter, (void *)ctx, r,
> r->connection);
> }
>
> static apr_status_t my_input_filter (ap_filter_t * f, apr_bucket_brigade *
> bb,
> ap_input_mode_t mode,apr_read_type_e
> block,
> apr_off_t readbytes)
> {
> //Function Body.
> }
>
>
>
> Regards,
> Ashish
>
>
> On Tue, Dec 2, 2008 at 2:50 PM, Sorin Manolache <[EMAIL PROTECTED]> wrote:
>
>> On Tue, Dec 2, 2008 at 10:12, Ashish Khare <[EMAIL PROTECTED]> wrote:
>> > Hi Ryan,
>> >
>> > I need to access header in the input filter.
>> >
>> > I means all the unparsed data sent by the client in the request which
>> > contains header information also.
>> >
>> > Please let me know how to do this.
>> >
>> > I have tried implementing the input filter but ap_get_brigade() call
>> returns
>> > empty brigade, which means it is returning only body and no headers.
>> >
>> > But i want to access header data.
>> >
>> > Please help me in this.
>> >
>>
>> Make your filter of type AP_FTYPE_PROTOCOL.
>>
>> S
>>
>
#include <httpd.h>
#include <http_config.h>
#include <http_request.h>
#include <util_filter.h>
#include <http_log.h>
static ap_filter_rec_t * globalInputFilter;
static int
my_insertfilter(request_rec * r) {
ap_add_input_filter_handle(globalInputFilter, NULL, r, r->connection);
return OK;
}
static int
read_brigade(apr_bucket_brigade *bb, request_rec *req) {
apr_bucket *e;
const char *data;
apr_size_t len;
for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb); e = APR_BUCKET_NEXT(e)) {
if (APR_BUCKET_IS_EOS(e))
return 1;
if (APR_BUCKET_IS_METADATA(e))
continue;
apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req, "%s", data);
}
return 0;
}
static apr_status_t
my_input_filter(ap_filter_t * f, apr_bucket_brigade *bb,
ap_input_mode_t mode, apr_read_type_e block,
apr_off_t readbytes) {
ap_get_brigade(f->next, bb, mode, block, readbytes);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, "In input filter");
read_brigade(bb, f->r);
return APR_SUCCESS;
}
static void
mod_my_register_hooks(apr_pool_t * p) {
ap_hook_create_request(my_insertfilter, NULL, NULL, APR_HOOK_MIDDLE);
globalInputFilter = ap_register_input_filter("MY_READ_INPUT", my_input_filter, NULL, AP_FTYPE_PROTOCOL);
}
module AP_MODULE_DECLARE_DATA input_module = {
STANDARD20_MODULE_STUFF,
NULL, /* module initializer */
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
mod_my_register_hooks,
};