# Hooks Class Reference
[Core Apache-related classes and functions]

Apache hook functions, wrapped in a class. More...

List of all members.

## Public Member Functions

int | saveOriginalFilename (request_rec *r)
| This is the hook method for the map_to_storage hook.
int | saveStateBeforeRewriteRules (request_rec *r)
| The default .htaccess provided by on Rails on Rails (that is, before version 2.1.0) has the following mod_rewrite rules in it:.
int | startBlockingModDir (request_rec *r)
| mod_dir does the following: If r->filename is a directory, and the URI doesn't end with a slash, then it will redirect the browser to an URI with a slash.
int | startBlockingModAutoIndex (request_rec *r)
| mod_autoindex will try to display a directory index for URIs that map to a directory.

## Detailed Description

Apache hook functions, wrapped in a class.

## Member Function Documentation

int Hooks::saveOriginalFilename | ( | request_rec * | r | ) | `[inline]`

This is the hook method for the map_to_storage hook.

Apache's final map_to_storage hook method (defined in core.c) will do the following:

If r->filename doesn't exist, then it will change the filename to the following form:

A/B

A is top-most directory that exists. B is the first filename piece that normally follows A. For example, suppose that a website's DocumentRoot is /website, on server http://test.com/. Suppose that there's also a directory /website/images. No other files or directories exist in /website.

If we access: then r->filename will be: http://test.com/foo/bar /website/foo http://test.com/foo/bar/baz /website/foo http://test.com/images/foo/bar /website/images/foo

We obviously don't want this to happen because it'll interfere with our page cache file search code. So here we save the original value of r->filename so that we can use it later.

int Hooks::saveStateBeforeRewriteRules | ( | request_rec * | r | ) | `[inline]`

The default .htaccess provided by on Rails on Rails (that is, before version 2.1.0) has the following mod_rewrite rules in it:.

RewriteEngine on RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

As a result, all requests that do not map to a filename will be redirected to dispatch.cgi (or dispatch.fcgi, if the user so specified). We don't want that to happen, so before mod_rewrite applies its rules, we save the current state. After mod_rewrite has applied its rules, undoRedirectionToDispatchCgi() will check whether mod_rewrite attempted to perform an internal redirection to dispatch.(f)cgi. If so, then it will revert the state to the way it was before mod_rewrite took place.

int Hooks::startBlockingModAutoIndex | ( | request_rec * | r | ) | `[inline]`

mod_autoindex will try to display a directory index for URIs that map to a directory.

This is undesired because of page caching semantics. Suppose that a Rails application has an ImagesController which has page caching enabled, and thus also a 'public/images' directory. When the visitor visits /images we'll want the request to be forwarded to the Rails application, instead of displaying a directory index.

So in this hook method, we temporarily change some fields in the request structure in order to block mod_autoindex. In endBlockingModAutoIndex(), we restore the request structure to its former state.

int Hooks::startBlockingModDir | ( | request_rec * | r | ) | `[inline]`

mod_dir does the following: If r->filename is a directory, and the URI doesn't end with a slash, then it will redirect the browser to an URI with a slash.

For example, if you go to http://foo.com/images, then it will redirect you to http://foo.com/images/.

This behavior is undesired. Suppose that there is an ImagesController, and there's also a 'public/images' folder used for storing page cache files. Then we don't want mod_dir to perform the redirection.

So in startBlockingModDir(), we temporarily change some fields in the request structure in order to block mod_dir. In endBlockingModDir() we revert those fields to their old value.

The documentation for this class was generated from the following file:

- Hooks.cpp