HTTP Protocol Compliance - Apache HTTP Server Version 2.5
Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.5 Apache > HTTP Server > Documentation > Version 2.5 HTTP Protocol Compliance Available Languages: en | fr This document describes the mechanism to set a policy for HTTP protocol compliance for a given URL space by the origin servers or applications behind that URL space. For those who may have received an error message from a rejected policy, and need to know what the policy rejection means and what they might do to fix the error, each policy is described below.
Enforcing HTTP Protocol Compliance in Apache 2 Conditional Request Policy Content-Length Policy Content-Type Policy Keepalive Policy Freshness Lifetime / Maxage Policy No Cache Policy Validation Policy Vary Header Policy Protocol Version Policy See also Filters Enforcing HTTP Protocol Compliance in Apache 2 ¶ Related Modules Related Directives mod_policy PolicyConditional PolicyLength PolicyKeepalive PolicyType PolicyVary PolicyValidation PolicyNocache PolicyMaxage PolicyVersion The HTTP protocol follows the robustness principle as described in RFC 1122 , which states "Be liberal in what you accept, and conservative in what you send" .
As a result of this principle, HTTP clients will compensate for and recover from incorrect or misconfigured responses, or responses that are uncacheable. As a website is scaled up to face greater and greater traffic loads, suboptimal or misconfigured applications or server configurations can threaten both the stability and scalability of the website, as well as the hosting costs associated with it. A website can also scale up to face greater configuration complexity, and it can be increasingly difficult to detect and keep track of suboptimally configured URL spaces on a given server.
Eventually a point is reached where the principle "conservative in what you send" needs to be enforced by the server administrator. The mod_policy module provides a set of filters which can be applied to a server, allowing key features of the HTTP protocol to be explicitly tested, and non compliant responses logged as warnings, or rejected outright as an error. Each filter can be applied separately, allowing the administrator to pick and choose which policies should be enforced depending on the circumstances of their environment.
The filters might be placed in testing and staging environments for the benefit of application and website developers, or may be applied to production servers to protect infrastructure from systems outside the administrator's direct control. In the above example, an Apache httpd server has been placed between the application server and the internet at large, and configured to cache responses from the application server.
The mod_policy filters have been added to enforce support for cacheable content and conditional requests, ensuring that both mod_cache and public caches on the internet are fully able to cache content created by the restful application server efficiently. In the above simpler example, a static server serving highly cacheable content has a set of policies applied to ensure that the server configuration conforms to a minimum level of compliance.
Conditional Request Policy ¶ Related Modules Related Directives mod_policy PolicyConditional This policy will be rejected if the server does not correctly respond to a conditional request with the appropriate status code. Conditional requests form the mechanism by which an HTTP cache makes stale content fresh again, and particularly for content with short freshness lifetimes, lack of support for conditional requests can add avoidable load to the server.
Most specifically, the existence of any of following headers in the request makes the request conditional: If-Match If the provided ETag in the If-Match header does not match the ETag of the response, the server should return 412 Precondition Failed . Full details of how to handle an If-Match header can be found in RFC 2616 . If-None-Match If the provided ETag in the If-None-Match header matches the ETag of the response, the server should return either 304 Not Modified for GET/HEAD requests, or 412 Precondition Failed for other methods.
Full details of how to handle an If-None-Match header can be found in RFC 2616 . If-Modified-Since If the provided date in the If-Modified-Since header is older than the Last-Modified header of the response, the server should return 304 Not Modified . Full details of how to handle an If-Modified-Since header can be found in RFC 2616 . If-Unmodified-Since If the provided date in the If-Modified-Since header is newer than the Last-Modified header of the response, the server should return 412 Precondition Failed .
Full details of how to handle an If-Unmodified-Since header can be found in RFC 2616 . If-Range If the provided ETag or date in the If-Range header matches the ETag or Last-Modified of the response, and a valid Range is present, the server should return 206 Partial Response . Full details of how to handle an If-Range header can be found in RFC 2616 . If the response is detected to have been successful (a 2xx response), but was conditional and one of the responses above was expected instead, this policy will be rejected.
Responses that indicate a redirect or a failure of some kind (3xx, 4xx, 5xx) will be ignored by this policy. This policy is implemented by the POLICY_CONDITIONAL filter. Content-Length Policy ¶ Related Modules Related Directives mod_policy PolicyLength This policy will be rejected if the server response does not contain an explicit Content-Length header. There are a number of ways of determining the length of a response body, described in full in RFC 2616 (Message Length).
When the Content-Length header is present, the size of the body is declared at the start of the response. If this information is missing, an HTTP cache might choose to ignore the response, as it does not know in advance whether the response will fit within the cache's defined limits. HTTP/1.1 defines the Transfer-Encoding header as an alternative to Content-Length , allowing the end of the response to be indicated to the client without the client having to know the length beforehand.
However, when HTTP/1.0 requests are processed, and no Content-Length is specified, the only mechanism available to the server to indicate the end of the request is to drop the connection. In an environment containing load balancers, this can cause the keepalive mechanism to be bypassed. If the response is detected to have been successful (a 2xx response), and has a response body (this excludes 204 No Content ), and the Content-Length header is missing, this policy will be rejected.
Responses that indicate a redirect or a failure of some kind (3xx, 4xx, 5xx) will be ignored by this policy. It should be noted that some modules, such as mod_proxy , add their own Content-Length header should the response be small enough for it to have been possible to read the response lacking such a header in one go. This may cause small responses to pass this policy, while larger responses may fail for the same URL.
This policy is implemented by the POLICY_LENGTH filter. Content-Type Policy ¶ Related Modules Related Directives mod_policy PolicyType This policy will be rejected if the server response does not contain an explicit and syntactically correct Content-Type header that matches the server defined pattern. The media type of the body is placed in the Content-Type header, and the format of the header is described in full in RFC 2616 (Media Types).
A syntactically valid content type might look as follows: Content-Type: text/html; charset=iso-8859-1 Invalid content types might include: # invalid Content-Type: foo # blank Content-Type: The server administrator has the option to restrict the policy to one or more specific types, or could specify a general wildcard type such as */* . This policy is implemented by the POLICY_TYPE filter. Keepalive Policy ¶ Related Module
The rest of this page is on the live site.