/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* http_protocol.c --- routines which directly communicate with the client.
*
* Code originally by Rob McCool; much redone by Robert S. Thau
* and the Apache Software Foundation.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#include "apr_signal.h"
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_log.h" /* For errors detected in basic auth common
* support code... */
#include "apr_date.h" /* For apr_date_parse_http and APR_DATE_BAD */
#include "util_charset.h"
#include "util_ebcdic.h"
#include "util_time.h"
#include "ap_mpm.h"
#include "mod_core.h"
#include <stdarg.h>
#endif
#include <unistd.h>
#endif
/* New Apache routine to map status codes into array indicies
* e.g. 100 -> 0, 101 -> 1, 200 -> 2 ...
* The number of status lines must equal the value of
* RESPONSE_CODES (httpd.h) and must be listed in order.
* No gaps are allowed between X00 and the largest Xnn
* for any X (see ap_index_of_response).
* When adding a new code here, add a define to httpd.h
* as well.
*/
{
"100 Continue",
"101 Switching Protocols",
"102 Processing",
"200 OK",
"201 Created",
"202 Accepted",
"203 Non-Authoritative Information",
"204 No Content",
"205 Reset Content",
"206 Partial Content",
"207 Multi-Status",
"208 Already Reported",
NULL, /* 209 */
NULL, /* 210 */
NULL, /* 211 */
NULL, /* 212 */
NULL, /* 213 */
NULL, /* 214 */
NULL, /* 215 */
NULL, /* 216 */
NULL, /* 217 */
NULL, /* 218 */
NULL, /* 219 */
NULL, /* 220 */
NULL, /* 221 */
NULL, /* 222 */
NULL, /* 223 */
NULL, /* 224 */
NULL, /* 225 */
"226 IM Used",
"300 Multiple Choices",
"301 Moved Permanently",
"302 Found",
"303 See Other",
"304 Not Modified",
"305 Use Proxy",
NULL, /* 306 */
"307 Temporary Redirect",
"308 Permanent Redirect",
"400 Bad Request",
"401 Unauthorized",
"402 Payment Required",
"403 Forbidden",
"404 Not Found",
"405 Method Not Allowed",
"406 Not Acceptable",
"407 Proxy Authentication Required",
"408 Request Timeout",
"409 Conflict",
"410 Gone",
"411 Length Required",
"412 Precondition Failed",
"413 Request Entity Too Large",
"414 Request-URI Too Long",
"415 Unsupported Media Type",
"416 Requested Range Not Satisfiable",
"417 Expectation Failed",
"418 I'm A Teapot",
NULL, /* 419 */
NULL, /* 420 */
NULL, /* 421 */
"422 Unprocessable Entity",
"423 Locked",
"424 Failed Dependency",
NULL, /* 425 */
"426 Upgrade Required",
NULL, /* 427 */
"428 Precondition Required",
"429 Too Many Requests",
NULL, /* 430 */
"431 Request Header Fields Too Large",
"500 Internal Server Error",
"501 Not Implemented",
"502 Bad Gateway",
"503 Service Unavailable",
"504 Gateway Timeout",
"505 HTTP Version Not Supported",
"506 Variant Also Negotiates",
"507 Insufficient Storage",
"508 Loop Detected",
NULL, /* 509 */
"510 Not Extended",
"511 Network Authentication Required"
};
)
/* The index of the first bit field that is used to index into a limit
* bitmask. M_INVALID + 1 to METHOD_NUMBER_LAST.
*/
/* The max method number. Method numbers are used to shift bitmasks,
* so this cannot exceed 63, and all bits high is equal to -1, which is a
* special flag, so the last bit used has index 62.
*/
static int is_mpm_running(void)
{
int mpm_state = 0;
return 0;
}
if (mpm_state == AP_MPMQ_STOPPING) {
return 0;
}
return 1;
}
{
int ka_sent = 0;
"close");
/* The following convoluted conditional determines whether or not
* the current connection should remain persistent after this response
* (a.k.a. HTTP Keep-Alive) and whether or not the output message
* body should use the HTTP/1.1 chunked transfer-coding. In English,
*
* IF we have not marked this connection as errored;
* and the client isn't expecting 100-continue (PR47087 - more
* input here could be the client continuing when we're
* closing the request).
* and the response body has a defined length due to the status code
* being 304 or 204, the request method being HEAD, already
* having defined Content-Length or Transfer-Encoding: chunked, or
* the request version being HTTP/1.1 and thus capable of being set
* as chunked [we know the (r->chunked = 1) side-effect is ugly];
* and the server configuration enables keep-alive;
* and the server configuration has a reasonable inter-request timeout;
* and there is no maximum # requests or the max hasn't been reached;
* and the response status does not require a close;
* and the response generator has not already indicated close;
* and the client did not request non-persistence (Connection: close);
* and we haven't been configured to ignore the buggy twit
* or they're a buggy twit coming through a HTTP/1.1 proxy
* and the client is requesting an HTTP/1.0-style keep-alive
* or the client claims to be HTTP/1.1 compliant (perhaps a proxy);
* and this MPM process is not already exiting
* THEN we can be persistent, which requires more headers be output.
*
* Note that the condition evaluation order is extremely important.
*/
&& !r->expecting_100
&& ((r->status == HTTP_NOT_MODIFIED)
|| (r->status == HTTP_NO_CONTENT)
|| r->header_only
|| ap_find_last_token(r->pool,
"Transfer-Encoding"),
"chunked")
&& r->server->keep_alive
&& (r->server->keep_alive_timeout > 0)
&& ((r->server->keep_alive_max == 0)
|| (left > 0))
&& !ap_status_drops_connection(r->status)
&& !wimpy
&& is_mpm_running()) {
r->connection->keepalives++;
/* If they sent a Keep-Alive token, send one back */
if (ka_sent) {
if (r->server->keep_alive_max) {
left));
}
else {
}
}
return 1;
}
/* Otherwise, we need to indicate that we will be closing this
* connection immediately after the current response.
*
* We only really need to send "close" to HTTP/1.1 clients, but we
* always send it anyway, because a broken proxy may identify itself
* as HTTP/1.0, but pass our request along with our HTTP/1.1 tag
* to a HTTP/1.1 client. Better safe than sorry.
*/
if (!wimpy) {
}
/*
* If we had previously been a keepalive connection and this
* is the last one, then bump up the number of keepalives
* we've had
*/
&& r->server->keep_alive_max
&& !left) {
r->connection->keepalives++;
}
return 0;
}
{
/* A server MUST use the strong comparison function (see section 13.3.3)
* to compare the entity tags in If-Match.
*/
if (if_match[0] == '*'
return AP_CONDITION_STRONG;
}
else {
return AP_CONDITION_NOMATCH;
}
}
return AP_CONDITION_NONE;
}
{
const char *if_unmodified;
if (if_unmodified) {
/* All of our comparisons must be in seconds, because that's the
* highest time resolution the HTTP specification allows.
*/
if (mtime == APR_DATE_BAD) {
}
if (!reqtime) {
}
/* weak matches not allowed with Range requests */
return AP_CONDITION_NOMATCH;
}
else {
return AP_CONDITION_WEAK;
}
}
else {
return AP_CONDITION_STRONG;
}
}
else {
return AP_CONDITION_NOMATCH;
}
}
return AP_CONDITION_NONE;
}
{
if (if_nonematch != NULL) {
if (if_nonematch[0] == '*') {
return AP_CONDITION_STRONG;
}
/* See section 13.3.3 for rules on how to determine if two entities tags
* match. The weak comparison function can only be used with GET or HEAD
* requests.
*/
if (r->method_number == M_GET) {
return AP_CONDITION_STRONG;
}
}
else {
return AP_CONDITION_WEAK;
}
}
}
}
return AP_CONDITION_STRONG;
}
return AP_CONDITION_NOMATCH;
}
return AP_CONDITION_NONE;
}
{
const char *if_modified_since;
!= NULL) {
/* All of our comparisons must be in seconds, because that's the
* highest time resolution the HTTP specification allows.
*/
if (mtime == APR_DATE_BAD) {
}
if (!reqtime) {
}
/* weak matches not allowed with Range requests */
return AP_CONDITION_NOMATCH;
}
else {
return AP_CONDITION_WEAK;
}
}
else {
return AP_CONDITION_STRONG;
}
}
else {
return AP_CONDITION_NOMATCH;
}
}
return AP_CONDITION_NONE;
}
{
if (if_range[0] == '"') {
return AP_CONDITION_STRONG;
}
else {
return AP_CONDITION_NOMATCH;
}
}
else {
/* All of our comparisons must be in seconds, because that's the
* highest time resolution the HTTP specification allows.
*/
if (mtime == APR_DATE_BAD) {
}
if (!reqtime) {
}
/* weak matches not allowed with Range requests */
return AP_CONDITION_NOMATCH;
}
else {
return AP_CONDITION_STRONG;
}
}
else {
return AP_CONDITION_NOMATCH;
}
}
}
return AP_CONDITION_NONE;
}
{
/* Check for conditional requests --- note that we only want to do
* this if we are successful so far and we are not processing a
* subrequest or an ErrorDocument.
*
* The order of the checks is important, since ETag checks are supposed
* to be more accurate than checks relative to the modification time.
* However, not all documents are guaranteed to *have* ETags, and some
* might have Last-Modified values w/o ETags, so this gets a little
* complicated.
*/
return OK;
}
/* If an If-Match request-header field was given
* AND the field value is not "*" (meaning match anything)
* AND if our strong ETag does not match any entity tag in that field,
* respond with a status of 412 (Precondition Failed).
*/
if (AP_CONDITION_NOMATCH == cond) {
return HTTP_PRECONDITION_FAILED;
}
/* Else if a valid If-Unmodified-Since request-header field was given
* AND the requested resource has been modified since the time
* specified in this field, then the server MUST
* respond with a status of 412 (Precondition Failed).
*/
if (AP_CONDITION_NOMATCH == cond) {
not_modified = 0;
}
else if (cond >= AP_CONDITION_WEAK) {
return HTTP_PRECONDITION_FAILED;
}
/* If an If-None-Match request-header field was given
* AND the field value is "*" (meaning match anything)
* OR our ETag matches any of the entity tags in that field, fail.
*
* If the request method was GET or HEAD, failure means the server
* SHOULD respond with a 304 (Not Modified) response.
* For all other request methods, failure means the server MUST
* respond with a status of 412 (Precondition Failed).
*
* GET or HEAD allow weak etag comparison, all other methods require
* strong comparison. We can only use weak if it's not a range request.
*/
if (AP_CONDITION_NOMATCH == cond) {
not_modified = 0;
}
else if (cond >= AP_CONDITION_WEAK) {
if (r->method_number == M_GET) {
if (not_modified) {
not_modified = 1;
}
}
else {
return HTTP_PRECONDITION_FAILED;
}
}
/* If a valid If-Modified-Since request-header field was given
* AND it is a GET or HEAD request
* AND the requested resource has not been modified since the time
* specified in this field, then the server MUST
* respond with a status of 304 (Not Modified).
* A date later than the server's current request time is invalid.
*/
if (AP_CONDITION_NOMATCH == cond) {
not_modified = 0;
}
else if (cond >= AP_CONDITION_WEAK) {
if (r->method_number == M_GET) {
if (not_modified) {
not_modified = 1;
}
}
}
/* If an If-Range and an Range header is present, we must return
* 200 OK. The byterange filter will convert it to a range response.
*/
if (cond > AP_CONDITION_NONE) {
return OK;
}
if (not_modified == 1) {
return HTTP_NOT_MODIFIED;
}
return OK;
}
/**
* Singleton registry of additional methods. This maps new method names
* such as "MYGET" to methnums, which are int offsets into bitmasks.
*
* This follows the same technique as standard M_GET, M_POST, etc. These
* are dynamically assigned when modules are loaded and <Limit GET MYGET>
* directives are processed.
*/
int methnum)
{
}
/* This internal function is used to clear the method registry
* and reset the cur_method_number counter.
*/
{
return APR_SUCCESS;
}
{
/* put all the standard methods into the registry hash to ease the
mapping operations between name and number */
}
{
int *methnum;
if (methods_registry == NULL) {
}
return M_INVALID;
}
/* Check if the method was previously registered. If it was
* return the associated method number.
*/
return *methnum;
if (cur_method_number > METHOD_NUMBER_LAST) {
/* The method registry has run out of dynamically
* assignable method numbers. Log this and return M_INVALID.
*/
"Maximum new request methods %d reached while "
"registering method %s.",
return M_INVALID;
}
return cur_method_number++;
}
{
/* Note: the following code was generated by the "shilka" tool from
the "cocom" parsing/compilation toolkit. It is an optimized lookup
based on analysis of the input keywords. Postprocessing was done
on the shilka output, but the basic structure and analysis is
from there. Should new HTTP methods be added, then manual insertion
into this code is fine, or simply re-running the shilka tool on
the appropriate input. */
/* Note: it is also quite reasonable to just use our method_registry,
but I'm assuming (probably incorrectly) we want more speed here
(based on the optimizations the previous code was doing). */
switch (len)
{
case 3:
switch (method[0])
{
case 'P':
? M_PUT : UNKNOWN_METHOD);
case 'G':
? M_GET : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 4:
switch (method[0])
{
case 'H':
? M_GET : UNKNOWN_METHOD);
case 'P':
? M_POST : UNKNOWN_METHOD);
case 'M':
? M_MOVE : UNKNOWN_METHOD);
case 'L':
? M_LOCK : UNKNOWN_METHOD);
case 'C':
? M_COPY : UNKNOWN_METHOD);
case 'B':
? M_BREW : UNKNOWN_METHOD);
case 'W':
? M_WHEN : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 5:
switch (method[2])
{
case 'T':
? M_PATCH : UNKNOWN_METHOD);
case 'R':
? M_MERGE : UNKNOWN_METHOD);
case 'C':
? M_MKCOL : UNKNOWN_METHOD);
case 'B':
? M_LABEL : UNKNOWN_METHOD);
case 'A':
? M_TRACE : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 6:
switch (method[0])
{
case 'U':
switch (method[5])
{
case 'K':
? M_UNLOCK : UNKNOWN_METHOD);
case 'E':
? M_UPDATE : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 'R':
? M_REPORT : UNKNOWN_METHOD);
case 'D':
? M_DELETE : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 7:
switch (method[1])
{
case 'P':
? M_OPTIONS : UNKNOWN_METHOD);
case 'O':
? M_CONNECT : UNKNOWN_METHOD);
case 'H':
? M_CHECKIN : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 8:
switch (method[0])
{
case 'P':
? M_PROPFIND : UNKNOWN_METHOD);
case 'C':
? M_CHECKOUT : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 9:
? M_PROPPATCH : UNKNOWN_METHOD);
case 10:
switch (method[0])
{
case 'U':
? M_UNCHECKOUT : UNKNOWN_METHOD);
case 'M':
? M_MKACTIVITY : UNKNOWN_METHOD);
default:
return UNKNOWN_METHOD;
}
case 11:
? M_MKWORKSPACE : UNKNOWN_METHOD);
case 15:
case 16:
default:
return UNKNOWN_METHOD;
}
/* NOTREACHED */
}
/* Get the method number associated with the given string, assumed to
* contain an HTTP method. Returns M_INVALID if not recognized.
*
* This is the first step toward placing method names in a configurable
* list. Hopefully it (and other routines) can eventually be moved to
* something like a mod_http_methods.c, complete with config stuff.
*/
{
if (which != UNKNOWN_METHOD)
return which;
/* check if the method has been dynamically registered */
if (methods_registry != NULL) {
return *methnum;
}
}
return M_INVALID;
}
/*
* Turn a known method number into a name.
*/
{
/* scan through the hash table, looking for a value that matches
the provided method number. */
const void *key;
void *val;
return key;
}
/* it wasn't found in the hash */
return NULL;
}
/* The index is found by its offset from the x00 code of each level.
* Although this is fast, it will need to be replaced if some nutcase
* decides to define a high-numbered code before the lower numbers.
* If that sad event occurs, replace the code below with a linear search
* from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1];
* or use NULL to fill the gaps.
*/
{
int i, pos;
return LEVEL_500;
}
for (i = 0; i < 5; i++) {
status -= 100;
if (status < 100) {
return pos;
}
else {
return LEVEL_500; /* status unknown (falls in gap) */
}
}
}
return LEVEL_500; /* 600 or above is also illegal */
}
{
}
/* Build the Allow field-value from the request handler method mask.
*/
{
/* For TRACE below */
const void *key;
void *val;
/* the M_GET method actually refers to two methods */
}
}
/* TRACE is tested on a per-server basis */
/* ### this is rather annoying. we should enforce registration of
### these methods */
}
}
{
if (r->assbackwards) {
return DECLINED;
}
/* the request finalization will send an EOS, which will flush all
* the headers out (including the Allow header)
*/
return OK;
}
{
if (!ct) {
r->content_type = NULL;
}
r->content_type = ct;
}
}
{
: "bytes");
}
const char *prefix,
const char *key,
const char *suffix)
{
}
else {
}
return result;
}
/* construct and return the default error message for a given
* HTTP defined error code
*/
request_rec *r,
const char *location)
{
apr_pool_t *p = r->pool;
switch (status) {
case HTTP_MOVED_PERMANENTLY:
case HTTP_MOVED_TEMPORARILY:
case HTTP_TEMPORARY_REDIRECT:
case HTTP_PERMANENT_REDIRECT:
return(apr_pstrcat(p,
"<p>The document has moved <a href=\"",
"\">here</a>.</p>\n",
NULL));
case HTTP_SEE_OTHER:
return(apr_pstrcat(p,
"<p>The answer to your request is located "
"<a href=\"",
"\">here</a>.</p>\n",
NULL));
case HTTP_USE_PROXY:
return(apr_pstrcat(p,
"<p>This resource is only accessible "
"through the proxy\n",
"<br />\nYou will need to configure "
"your client to use that proxy.</p>\n",
NULL));
case HTTP_UNAUTHORIZED:
return("<p>This server could not verify that you\n"
"are authorized to access the document\n"
"requested. Either you supplied the wrong\n"
"credentials (e.g., bad password), or your\n"
"browser doesn't understand how to supply\n"
"the credentials required.</p>\n");
case HTTP_BAD_REQUEST:
return(add_optional_notes(r,
"<p>Your browser sent a request that "
"this server could not understand.<br />\n",
"error-notes",
"</p>\n"));
case HTTP_FORBIDDEN:
s1 = apr_pstrcat(p,
"<p>You don't have permission to access ",
"\non this server.<br />\n",
NULL);
case HTTP_NOT_FOUND:
return(apr_pstrcat(p,
"<p>The requested URL ",
" was not found on this server.</p>\n",
NULL));
case HTTP_METHOD_NOT_ALLOWED:
return(apr_pstrcat(p,
"<p>The requested method ",
" is not allowed for the URL ",
".</p>\n",
NULL));
case HTTP_NOT_ACCEPTABLE:
s1 = apr_pstrcat(p,
"<p>An appropriate representation of the "
"requested resource ",
" could not be found on this server.</p>\n",
NULL);
case HTTP_MULTIPLE_CHOICES:
case HTTP_LENGTH_REQUIRED:
s1 = apr_pstrcat(p,
"<p>A request of the requested method ",
" requires a valid Content-length.<br />\n",
NULL);
case HTTP_PRECONDITION_FAILED:
return(apr_pstrcat(p,
"<p>The precondition on the request "
"for the URL ",
" evaluated to false.</p>\n",
NULL));
case HTTP_NOT_IMPLEMENTED:
s1 = apr_pstrcat(p,
"<p>",
" not supported.<br />\n",
NULL);
case HTTP_BAD_GATEWAY:
"response from an upstream server.<br />" CRLF;
case HTTP_VARIANT_ALSO_VARIES:
return(apr_pstrcat(p,
"<p>A variant for the requested "
"resource\n<pre>\n",
"\n</pre>\nis itself a negotiable resource. "
"This indicates a configuration error.</p>\n",
NULL));
case HTTP_REQUEST_TIME_OUT:
return("<p>Server timeout waiting for the HTTP request from the client.</p>\n");
case HTTP_GONE:
return(apr_pstrcat(p,
"<p>The requested resource<br />",
"<br />\nis no longer available on this server "
"and there is no forwarding address.\n"
"Please remove all references to this "
"resource.</p>\n",
NULL));
return(apr_pstrcat(p,
"The requested resource<br />",
"does not allow request data with ",
" requests, or the amount of data provided in\n"
"the request exceeds the capacity limit.\n",
NULL));
s1 = "<p>The requested URL's length exceeds the capacity\n"
"limit for this server.<br />\n";
return("<p>The supplied request data is not in a format\n"
"acceptable for processing by this resource.</p>\n");
return("<p>None of the range-specifier values in the Range\n"
"request-header field overlap the current extent\n"
"of the selected resource.</p>\n");
case HTTP_EXPECTATION_FAILED:
if (s1)
s1 = apr_pstrcat(p,
"<p>The expectation given in the Expect request-header\n"
"field could not be met by this server.\n"
"The client sent<pre>\n Expect: ",
NULL);
else
s1 = "<p>No expectation was seen, the Expect request-header \n"
"field was not presented by the client.\n";
"<p>Only the 100-continue expectation is supported.</p>\n");
return("<p>The server understands the media type of the\n"
"request entity, but was unable to process the\n"
"contained instructions.</p>\n");
case HTTP_LOCKED:
return("<p>The requested resource is currently locked.\n"
"The lock must be released or proper identification\n"
"given before the method can be applied.</p>\n");
case HTTP_FAILED_DEPENDENCY:
return("<p>The method could not be performed on the resource\n"
"because the requested action depended on another\n"
"action and that other action failed.</p>\n");
case HTTP_UPGRADE_REQUIRED:
return("<p>The requested resource can only be retrieved\n"
"using SSL. The server is willing to upgrade the current\n"
"connection to SSL, but your client doesn't support it.\n"
"Either upgrade your client, or try requesting the page\n"
"using https://\n");
return("<p>The request is required to be conditional.</p>\n");
case HTTP_TOO_MANY_REQUESTS:
return("<p>The user has sent too many requests\n"
"in a given amount of time.</p>\n");
return("<p>The server refused this request because\n"
"the request header fields are too large.</p>\n");
return("<p>The method could not be performed on the resource\n"
"because the server is unable to store the\n"
"representation needed to successfully complete the\n"
"request. There is insufficient free space left in\n"
"your storage allocation.</p>\n");
case HTTP_SERVICE_UNAVAILABLE:
return("<p>The server is temporarily unable to service your\n"
"request due to maintenance downtime or capacity\n"
"problems. Please try again later.</p>\n");
case HTTP_GATEWAY_TIME_OUT:
return("<p>The gateway did not receive a timely response\n"
"from the upstream server or application.</p>\n");
case HTTP_LOOP_DETECTED:
return("<p>The server terminated an operation because\n"
"it encountered an infinite loop.</p>\n");
case HTTP_NOT_EXTENDED:
return("<p>A mandatory extension policy in the request is not\n"
"accepted by the server for this resource.</p>\n");
return("<p>The client needs to authenticate to gain\n"
"network access.</p>\n");
case HTTP_IM_A_TEAPOT:
return("<p>The resulting entity body MAY be short and\n"
"stout.</p>\n");
default: /* HTTP_INTERNAL_SERVER_ERROR */
/*
* This comparison to expose error-notes could be modified to
* use a configuration directive and export based on that
* directive. For now "*" is used to designate an error-notes
* that is totally safe for any user to see (ie lacks paths,
* database passwords, etc.)
*/
"error-notes")) != NULL)
}
else {
return(apr_pstrcat(p,
"<p>The server encountered an internal "
"error or\n"
"misconfiguration and was unable to complete\n"
"your request.</p>\n"
"<p>Please contact the server "
"administrator at \n ",
ap_escape_html(r->pool,
r->server->server_admin),
" to inform them of the time this "
"error occurred,\n"
" and the actions you performed just before "
"this error.</p>\n"
"<p>More information about this error "
"may be available\n"
"in the server error log.</p>\n",
NULL));
}
/*
* It would be nice to give the user the information they need to
* fix the problem directly since many users don't have access to
* the error_log (think University sites) even though they can easily
* get this error by misconfiguring an htaccess file. However, the
* e error notes tend to include the real file pathname in this case,
* which some people consider to be a breach of privacy. Until we
* can figure out a way to remove the pathname, leave this commented.
*
* if ((error_notes = apr_table_get(r->notes,
* "error-notes")) != NULL) {
* return(apr_pstrcat(p, error_notes, "<p />\n", NULL);
* }
* else {
* return "";
* }
*/
}
}
/* We should have named this send_canned_response, since it is used for any
* response that can be generated by the server from the request record.
* This includes all 204 (no content), 3xx (redirect), 4xx (client error),
* and 5xx (server error) messages that have not been redirected to another
* handler via the ErrorDocument feature.
*/
{
char *custom_response;
/* At this point, we are starting the response over, so we have to reset
* this value.
*/
r->eos_sent = 0;
/* and we need to get rid of any RESOURCE filters that might be lurking
* around, thinking they are in the middle of the original request
*/
r->output_filters = r->proto_output_filters;
/*
* It's possible that the Location field might be in r->err_headers_out
* instead of r->headers_out; use the latter if possible, else the
* former.
*/
}
/* We need to special-case the handling of 204 and 304 responses,
* since they have specific HTTP requirements and do not include a
* message body. Note that being assbackwards here is not an option.
*/
if (status == HTTP_NOT_MODIFIED) {
return;
}
if (status == HTTP_NO_CONTENT) {
return;
}
if (!r->assbackwards) {
/* For all HTTP/1.x responses for which we generate the message,
* we need to avoid inheriting the "normal status" header fields
* that may have been set by the request handler before the
* error or redirect, except for Location on external redirects.
*/
r->headers_out = r->err_headers_out;
r->err_headers_out = tmp;
}
else {
}
}
r->content_languages = NULL;
r->content_encoding = NULL;
r->clength = 0;
if (apr_table_get(r->subprocess_env,
"suppress-error-charset") != NULL) {
* charset later
*/
ap_set_content_type(r, "text/html");
}
else {
ap_set_content_type(r, "text/html; charset=iso-8859-1");
}
if ((status == HTTP_METHOD_NOT_ALLOWED)
|| (status == HTTP_NOT_IMPLEMENTED)) {
}
if (r->header_only) {
return;
}
}
/*
* We have a custom response output. This should only be
* a text-string to write back. But if the ErrorDocument
* was a local redirect and the requested resource failed
* for any reason, the custom_response will still hold the
* redirect URL. We don't really want to output this URL
* as a text message, so first check the custom response
* string to ensure that it is a text-string (using the
* same test used in ap_die(), i.e. does it start with a ").
*
* If it's not a text string, we've got a recursive error or
* an external redirect. If it's a recursive error, ap_die passes
* us the second error code so we can write both, and has already
* backed up to the original error. If it's an external redirect,
* it hasn't happened yet; we may never know if it fails.
*/
if (custom_response[0] == '\"') {
return;
}
}
{
const char *h1;
/* Accept a status_line set by a module, but only if it begins
* with the correct 3 digit status code
*/
if (r->status_line) {
char *end;
if (len >= 3
/* Since we passed the above check, we know that length three
* is equivalent to only a 3 digit numeric http status.
* RFC2616 mandates a trailing space, let's add it.
* If we have an empty reason phrase, we also add "Unknown Reason".
*/
if (len == 3) {
} else if (len == 4) {
}
title = r->status_line;
}
}
/* folks decided they didn't want the error code in the H1 text */
/* can't count on a charset filter being in place here,
* so do ebcdic->ascii translation explicitly (if needed)
*/
"<html><head>\n<title>", title,
NULL);
NULL);
if (recursive_error) {
ap_rvputs_proto_in_ascii(r, "<p>Additionally, a ",
"\nerror was encountered while trying to use an "
"ErrorDocument to handle the request.</p>\n", NULL);
}
}
}
/*
* Create a new method list with the specified number of preallocated
* extension slots.
*/
{
ml->method_mask = 0;
return ml;
}
/*
* Make a copy of a method list (primarily for subrequests that may
* subsequently change it; don't want them changing the parent's, too!).
*/
{
int i;
char **imethods;
char **omethods;
}
}
/*
* Return true if the specified HTTP method is in the provided
* method list.
*/
{
int methnum;
int i;
char **methods;
/*
* If it's one of our known methods, use the shortcut and check the
* bitmask.
*/
}
/*
* Otherwise, see if the method name is in the array or string names
*/
return 0;
}
for (i = 0; i < l->method_list->nelts; ++i) {
return 1;
}
}
return 0;
}
/*
* Add the specified method to a method list (if it isn't already there).
*/
{
int methnum;
int i;
const char **xmethod;
char **methods;
/*
* If it's one of our known methods, use the shortcut and use the
* bitmask.
*/
return;
}
/*
* Otherwise, see if the method name is in the array of string names.
*/
if (l->method_list->nelts != 0) {
for (i = 0; i < l->method_list->nelts; ++i) {
return;
}
}
}
}
/*
* Remove the specified method from a method list.
*/
const char *method)
{
int methnum;
char **methods;
/*
* If it's a known methods, either builtin or registered
* by a module, use the bitmask.
*/
return;
}
/*
* Otherwise, see if the method name is in the array of string names.
*/
if (l->method_list->nelts != 0) {
int i, j, k;
for (i = 0; i < l->method_list->nelts; ) {
}
--l->method_list->nelts;
}
else {
++i;
}
}
}
}
/*
* Reset a method list to be completely empty.
*/
{
l->method_mask = 0;
l->method_list->nelts = 0;
}