httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sorin Manolache" <sor...@gmail.com>
Subject Re: To Access header in Input Filter
Date Tue, 02 Dec 2008 12:49:12 GMT
On Tue, Dec 2, 2008 at 10:58, Ashish Khare <ashishrk@gmail.com> 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 <sorinm@gmail.com> wrote:
>
>> On Tue, Dec 2, 2008 at 10:12, Ashish Khare <ashishrk@gmail.com> 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
>>
>

Mime
View raw message