# Before and After Filters

Filters are called before a request is to be issued to the Network, and after when the request has terminated. All filters are registered at run-time, and filters can be cascaded so that one filter can call other filters and so on. Filters can also start new requests or terminate existing requests, so the set of possibilities is very big. Normally, filters do only handle metainformation about a resource. For example, the authentication filters looks to see if we have been asked to provide some credentials in order to access a URL. If so then it adds a protocol defined header to the request, and if not then the request just proceeds. Handling the actual data object is done by streams which can modify the contents of a data object.

The Library can handle local and global filters - local filters are associated with a single request and global filters are associated with all requests. That is, if you can decorate a request with a specialized filter or you can use a generalized filter for handling all requests. A global filter is useful if the filter is to be performed very often and local filters can either add to or override the global set of filters.

Often, a before and an after filter needs to share a context which is unique to this set of filters. There are various ways this can be handled by the Library. Either a context can associated at registration time or it can be built while the filters are run. The URL tree is a useful data object for keeping information associated with realms or sets of URLs.