views:

592

answers:

4

Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete classes ?

I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?

Thanks.

=== ADDENDUM ===

On the good advice of Kevin Davis, I just want to quickly elaborate on what Java Servlet Filters are. It is basically an HTTP request interceptor. A chain of filters can be configured between the raw receipt of the request and the final destination of the request. The request parameters (and cookies, headers etc. etc.) are passed to the first filter in the chain and each filter does something with them (or not) and then passes them up the chain (or not. eg. a caching filter may simply return the result, bypassing the rest of the chain and the endpoint).

One of the advantages is the ability to modify or enhance the web app without touching the original endpoint code.

Cheers.

A: 

In a typical Apache/PHP scenario, the answer is generally: No, there are no custom filters. However, there some solutions for problems solved with Java Servlet Filters:

You can create a .htaccess file to set those properties for a directory and its subdirectories.

phihag
+1  A: 

I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?

Django provides a framework of middleware hooks that can be used to alter input/output in request/response processing. See the Middleware documentation page for more details.

Simon Lieschke
A: 

Ruby on Rails has filters that serve this purpose

A new feature is Rack Middleware, which is similar to Django middleware

pjb3
A: 

In the PHP world, Zend Framework provides a plugin API for its front controller object that allows hooking of plugin objects between the pre-routing and post-dispatching phases. Although I didn't have a chance to work with Java servlets I assume this would match the descripton in your addendum. Anyway, this is not built into PHP, its framework dependent as with RoR or Django.

Ionuț G. Stan