This document describes changes to the Apache HTTPD API from version 2.2 to 2.4, that may be of interest to module/application developers and core hacks. At the time of writing, the 2.4 API is not finalised, and this document may serve to highlight points that call for further review.
API changes fall into two categories: APIs that are altogether new, and existing APIs that are expanded or changed. The latter are further divided into those where all changes are back-compatible (so existing modules can ignore them), and those that might require attention by maintainers. As with the transition from HTTPD 2.0 to 2.2, existing modules and applications will require recompiling and may call for some attention, but most should not require any substantial updating (although some may be able to take advantage of API changes to offer significant improvements).
For the purpose of this document, the API is split according
to the public header files. These headers are themselves the
reference documentation, and can be used to generate a browsable
HTML reference with make docs.
Introduces a new API to parse and evaluate boolean and algebraic expressions, including provision for a standard syntax and customised variants.
Introduces new API to enable apache child processes to serve different purposes.
ap_mpm_run is replaced by a new mpm hook.
Also ap_graceful_stop_signalled is lost, and
ap_mpm_register_timed_callback is new.
In addition to the existing regexp wrapper, a new higher-level API
ap_rxplus is now provided. This provides the capability to
compile Perl-style expressions like s/regexp/replacement/flags
and to execute them against arbitrary strings. Support for regexp
backreference.
Introduces an API for modules to allocate and manage memory slots (normally) for shared memory.
API to manage a shared object cache.
common structures for heartbeat modules (should this be public API?)
The function signature for ap_parse_htaccess has been
changed. A apr_table_t of individual directives allowed
for override must now be passed (override remains).
http_core.h.When possible, registering all access control hooks (including authentication and authorization hooks) using AP_AUTH_INTERNAL_PER_CONF is recommended. If all modules' access control hooks are registered with this flag, then whenever the server handles an internal sub-request that matches the same set of access control configuration directives as the initial request (which is the common case), it can avoid invoking the access control hooks another time.
If your module requires the old behavior and must perform access control checks on every sub-request with a different URI from the initial request, even if that URI matches the same set of access control configuration directives, then use AP_AUTH_INTERNAL_PER_URI.
Introduces the new provider framework for authn and authz
Introduces a commit_entity() function to the cache provider interface, allowing atomic writes to cache. Add a cache_status() hook to report the cache decision. Remove all private structures and functions from the public mod_cache.h header file.
This introduces low-level APIs to send arbitrary headers, and exposes functions to handle HTTP OPTIONS and TRACE.
Changes the disk format of the disk cache to support atomic cache updates without locking. The device/inode pair of the body file is embedded in the header file, allowing confirmation that the header and body belong to one another.
The mod_disk_cache module has been renamed to mod_cache_disk in order to be consistent with the naming of other modules within the server.
The API for
ap_get_scoreboard_worker is gratuitously made non-back-compatible as an alternative version is introduced. Additional proxy_balancer support. Child status stuff revamped.
I have yet to get a handle on this update.
A wrapper for APR proc and global mutexes in httpd.
NEW: ap_args_to_table
NEW: ap_recent_ctime_ex
In order to take advantage of per-module loglevel configuration, any
source file that calls the ap_log_* functions should declare
which module it belongs to. If the module's module_struct is called
foo_module, the following code can be used to remain
backward compatible with HTTPD 2.0 and 2.2:
Note: This is absolutely required for C++-language modules. It can be skipped for C-language modules, though that breaks module-specific log level support for files without it.
The number of parameters of the ap_log_* functions and the
definition of APLOG_MARK has changed. Normally, the change
is completely transparent. However, changes are required if a
module uses APLOG_MARK as a parameter to its own functions
or if a module calls ap_log_* without passing
APLOG_MARK. A module which uses wrappers
around ap_log_* typically uses both of these constructs.
The easiest way to change code which passes APLOG_MARK to
its own functions is to define and use a different macro that expands to
the parameters required by those functions, as APLOG_MARK
should only be used when calling ap_log_*
directly. In this way, the code will remain compatible with HTTPD 2.0
and 2.2.
Code which calls ap_log_* without passing
APLOG_MARK will necessarily differ between 2.4 and earlier
releases, as 2.4 requires a new third argument,
APLOG_MODULE_INDEX.
A server_rec pointer must be passed to
ap_log_error() when called after startup. This
was always appropriate, but there are even more limitations with
a NULL server_rec in 2.4 than in
previous releases. Beginning with 2.3.12, the global variable
ap_server_conf can always be used as
the server_rec parameter, as it will be
NULL only when it is valid to pass NULL
to ap_log_error(). ap_server_conf
should be used only when a more appropriate server_rec
is not available.
Consider the following changes to take advantage of the new
APLOG_TRACE1..8 log levels:
APLOG_DEBUG and
consider if one of the APLOG_TRACEn levels is
more appropriate.APLOG_TRACEn levels. If expensive
trace processing needs to be bypassed depending on the
configured log level, use the APLOGtracen
and APLOGrtracen macros to first check
if tracing is enabled.Modules sometimes add process id and/or thread id to their log messages. These ids are now logged by default, so it may not be necessary for the module to log them explicitly. (Users may remove them from the error log format, but they can be instructed to add it back if necessary for problem diagnosis.)
ap_default_type()ap_get_server_name()ap_get_server_name_for_url() instead. This new
function handles the odd case where the server name is an IPv6
literal address.ap_get_server_version()ap_get_server_description().
When generating output, where the amount of information
should be configurable by ServerTokens, use
ap_get_server_banner().ap_graceful_stop_signalled()ap_mpm_query(AP_MPMQ_MPM_STATE) and checking for
state AP_MPMQ_STOPPING.ap_max_daemons_limit, ap_my_generation,
and ap_threads_per_childap_mpm_query() query codes
AP_MPMQ_MAX_DAEMON_USED, AP_MPMQ_GENERATION,
and AP_MPMQ_MAX_THREADS, respectively.ap_mpm_query()ap_server_conf->process->pool
userdataap_state_query(AP_SQ_MAIN_STATE).ap_retained_data_create() and
ap_retained_data_get().apr_global_mutex_create(),
apr_proc_mutex_create()ap_mutex_register(),
ap_global_mutex_create(), and
ap_proc_mutex_create(); these allow your
mutexes to be configurable with
the CORE_PRIVATEdav_new_error()
and dav_new_error_tag()errno contained
information describing the failure. Now,
an apr_status_t parameter must be provided. Pass
0/APR_SUCCESS if there is no such error information, or a valid
apr_status_t value otherwise.mpm_default.h, DEFAULT_LOCKFILE,
DEFAULT_THREAD_LIMIT, DEFAULT_PIDLOG,
etc.DEFAULT_PIDLOG
and DEFAULT_REL_RUNTIMEDIR are now universally
available via ap_config.h.unixd_configap_unixd_config.suexec_enabled is 0,
also log the value of the new
field suexec_disabled_reason, which contains an
explanation of why it is not available.ExtendedStatus had to be
set to On, which in turn required that
mod_status was loaded. In 2.4, just
set ap_extended_status to 1 in a
pre-config hook and the extended status data will be
available.ap_args_to_table() would be
helpful.ap_parse_form_data().Content-Length
and Transfer-Encoding to see if a body was
specifiedap_request_has_body().ap_pool_cleanup_set_null().