SHARE
Facebook X Pinterest WhatsApp

Filtering I/O in Apache 2.0 Page 3

Written By
thumbnail Ryan Bloom
Ryan Bloom
Sep 20, 2000
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



The
first argument is a name for the filter. This
name is used throughout the
server to reference
that filter fuction. The second is the filter
function
we are registering. The final
argument is the type of filter. There are

currently two filter types, content and
connection. Content filters are any
filter
that modifies the data being sent. Connection
filters refer to filters
that dictate how the
data is sent over the network. For example, a
SSI filter
is a content filter while an SSL
filter is a connection filter.

Once the
filter has been registered, it must be added to
the current request’s
filter stack before it
will actually be called. This is done by
calling
ap_add_filter.

void
ap_add_filter(const char *name, void *ctx,
request_rec *r);

The first argument is
the name of the filter to add. This should be
the name
that was registered for the desired
filter. The second is a pointer to a
structure
that should be passed to the filter whenever it
is called. This
provides with a location to
store any data that they may need to save between

calls. The final argument is the request_rec
to pass to the filter when it is
called.

There are two more functions prototypes that must
be discussed. The first is
the prototype for
filters themselves.

apr_status_t
ap_filter_func(ap_filter_t *f, ap_bucket_brigade
*b);

The first argument is a pointer
to the current filter structure. This is where

the ctx passed to ap_add_filter is stored, as
well as a pointer to the next filter
on the
stack. The second is the current bucket brigade
to filter.

The second function is
ap_pass_brigade. This function passes bucket
brigades
from the current filter to the next
filter. The prototype is:

apr_status_t
ap_pass_brigade(ap_filter_t *filter,

ap_bucket_brigade
*bucket);

The first argument is a
pointer to the next filter to call, and the
second is the
bucket brigade to pass to that
filter.

That covers all of the basic
concepts for writing filters. In next month’s

article we will actually write a filter that can
be inserted into an Apache 2.0
server.

thumbnail Ryan Bloom

Ryan Bloom is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.