http_protocol.c revision a771451a437726073089edb17a7c9ed32f85fb1a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * The ASF licenses this file to You under the Apache License, Version 2.0
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * (the "License"); you may not use this file except in compliance with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Unless required by applicable law or agreed to in writing, software
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distributed under the License is distributed on an "AS IS" BASIS,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * See the License for the specific language governing permissions and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_protocol.c --- routines which directly communicate with the client.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Code originally by Rob McCool; much redone by Robert S. Thau
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * and the Apache Software Foundation.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_strings.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_buckets.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_lib.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_signal.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define APR_WANT_STDIO /* for sscanf */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#define APR_WANT_STRFUNC
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#define APR_WANT_MEMFUNC
64185f9824e42f21ca7b9ae6c004484215c031a7rbb#include "apr_want.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "util_filter.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "ap_config.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "httpd.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_core.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_protocol.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_main.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_request.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_vhost.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_log.h" /* For errors detected in basic auth common
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * support code... */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_date.h" /* For apr_date_parse_http and APR_DATE_BAD */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "util_charset.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "util_ebcdic.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "util_time.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "ap_mpm.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "mod_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#if APR_HAVE_STDARG_H
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include <stdarg.h>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if APR_HAVE_UNISTD_H
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include <unistd.h>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* New Apache routine to map status codes into array indicies
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * e.g. 100 -> 0, 101 -> 1, 200 -> 2 ...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * The number of status lines must equal the value of RESPONSE_CODES (httpd.h)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and must be listed in order.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char * const status_lines[RESPONSE_CODES] =
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb "100 Continue",
b6055b7832a0e4d0818416252fff5925aaebae4brbb "101 Switching Protocols",
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb "102 Processing",
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb#define LEVEL_200 3
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "200 OK",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "201 Created",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "202 Accepted",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "203 Non-Authoritative Information",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "204 No Content",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "205 Reset Content",
ee4a7424a2d75f6c2296459ce31bc4e02b923bcdrbb "206 Partial Content",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "207 Multi-Status",
48d7c43629323c8d5ee9f7bd0d194de0a376b391rbb#define LEVEL_300 11
d41217398f0e1031adbb6f5bd37f45737c805deftrawick "300 Multiple Choices",
d41217398f0e1031adbb6f5bd37f45737c805deftrawick "301 Moved Permanently",
d41217398f0e1031adbb6f5bd37f45737c805deftrawick "302 Found",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "303 See Other",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "304 Not Modified",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "305 Use Proxy",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "306 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "307 Temporary Redirect",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define LEVEL_400 19
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "400 Bad Request",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "401 Authorization Required",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "402 Payment Required",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "403 Forbidden",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "404 Not Found",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "405 Method Not Allowed",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "406 Not Acceptable",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "407 Proxy Authentication Required",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "408 Request Time-out",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "409 Conflict",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "410 Gone",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "411 Length Required",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "412 Precondition Failed",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "413 Request Entity Too Large",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "414 Request-URI Too Large",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "415 Unsupported Media Type",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "416 Requested Range Not Satisfiable",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "417 Expectation Failed",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "418 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "419 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "420 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "421 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "422 Unprocessable Entity",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "423 Locked",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "424 Failed Dependency",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* This is a hack, but it is required for ap_index_of_response
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * to work with 426.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "425 No code",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "426 Upgrade Required",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define LEVEL_500 46
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "500 Internal Server Error",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "501 Method Not Implemented",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "502 Bad Gateway",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "503 Service Temporarily Unavailable",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "504 Gateway Time-out",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "505 HTTP Version Not Supported",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "506 Variant Also Negotiates",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "507 Insufficient Storage",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "508 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "509 unused",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "510 Not Extended"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAPR_HOOK_STRUCT(
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_HOOK_LINK(insert_error_filter)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_IMPLEMENT_HOOK_VOID(insert_error_filter, (request_rec *r), (r))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* The index of the first bit field that is used to index into a limit
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * bitmask. M_INVALID + 1 to METHOD_NUMBER_LAST.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define METHOD_NUMBER_FIRST (M_INVALID + 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* The max method number. Method numbers are used to shift bitmasks,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * so this cannot exceed 63, and all bits high is equal to -1, which is a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * special flag, so the last bit used has index 62.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define METHOD_NUMBER_LAST 62
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int is_mpm_running(void)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int mpm_state = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (mpm_state == AP_MPMQ_STOPPING) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_DECLARE(int) ap_set_keepalive(request_rec *r)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int ka_sent = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int left = r->server->keep_alive_max - r->connection->keepalives;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int wimpy = ap_find_token(r->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_get(r->headers_out, "Connection"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "close");
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb const char *conn = apr_table_get(r->headers_in, "Connection");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* The following convoluted conditional determines whether or not
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the current connection should remain persistent after this response
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * (a.k.a. HTTP Keep-Alive) and whether or not the output message
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * body should use the HTTP/1.1 chunked transfer-coding. In English,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * IF we have not marked this connection as errored;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * and the response body has a defined length due to the status code
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * being 304 or 204, the request method being HEAD, already
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * having defined Content-Length or Transfer-Encoding: chunked, or
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb * the request version being HTTP/1.1 and thus capable of being set
ec727afb817df0e5202135278c0d2902923cc980stoddard * as chunked [we know the (r->chunked = 1) side-effect is ugly];
ec727afb817df0e5202135278c0d2902923cc980stoddard * and the server configuration enables keep-alive;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * and the server configuration has a reasonable inter-request timeout;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * and there is no maximum # requests or the max hasn't been reached;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * and the response status does not require a close;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * and the response generator has not already indicated close;
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * and the client did not request non-persistence (Connection: close);
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * and we haven't been configured to ignore the buggy twit
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * or they're a buggy twit coming through a HTTP/1.1 proxy
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * and the client is requesting an HTTP/1.0-style keep-alive
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * or the client claims to be HTTP/1.1 compliant (perhaps a proxy);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * and this MPM process is not already exiting
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * THEN we can be persistent, which requires more headers be output.
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb *
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * Note that the condition evaluation order is extremely important.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard if ((r->connection->keepalive != AP_CONN_CLOSE)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && ((r->status == HTTP_NOT_MODIFIED)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb || (r->status == HTTP_NO_CONTENT)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb || r->header_only
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb || apr_table_get(r->headers_out, "Content-Length")
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || ap_find_last_token(r->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_get(r->headers_out,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "Transfer-Encoding"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "chunked")
061c3874622b67beff724876b9bd1b1f291f2eaafielding || ((r->proto_num >= HTTP_VERSION(1,1))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && (r->chunked = 1))) /* THIS CODE IS CORRECT, see above. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && r->server->keep_alive
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (r->server->keep_alive_timeout > 0)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm && ((r->server->keep_alive_max == 0)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb || (left > 0))
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && !ap_status_drops_connection(r->status)
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb && !wimpy
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && !ap_find_token(r->pool, conn, "close")
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (!apr_table_get(r->subprocess_env, "nokeepalive")
2b484455736f4c30447aa852764f53282cbeb5ddrbb || apr_table_get(r->headers_in, "Via"))
2b484455736f4c30447aa852764f53282cbeb5ddrbb && ((ka_sent = ap_find_token(r->pool, conn, "keep-alive"))
2b484455736f4c30447aa852764f53282cbeb5ddrbb || (r->proto_num >= HTTP_VERSION(1,1)))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && is_mpm_running()) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb r->connection->keepalive = AP_CONN_KEEPALIVE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->connection->keepalives++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* If they sent a Keep-Alive token, send one back */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ka_sent) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->server->keep_alive_max) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(r->headers_out, "Keep-Alive",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_psprintf(r->pool, "timeout=%d, max=%d",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (int)apr_time_sec(r->server->keep_alive_timeout),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding left));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(r->headers_out, "Keep-Alive",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_psprintf(r->pool, "timeout=%d",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (int)apr_time_sec(r->server->keep_alive_timeout)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_mergen(r->headers_out, "Connection", "Keep-Alive");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Otherwise, we need to indicate that we will be closing this
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * connection immediately after the current response.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We only really need to send "close" to HTTP/1.1 clients, but we
061c3874622b67beff724876b9bd1b1f291f2eaafielding * always send it anyway, because a broken proxy may identify itself
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * as HTTP/1.0, but pass our request along with our HTTP/1.1 tag
95ed69df3d43a7d2758720bad8950f07587bdeb9bjh * to a HTTP/1.1 client. Better safe than sorry.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
2b484455736f4c30447aa852764f53282cbeb5ddrbb if (!wimpy) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb apr_table_mergen(r->headers_out, "Connection", "close");
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If we had previously been a keepalive connection and this
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * is the last one, then bump up the number of keepalives
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * we've had
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((r->connection->keepalive != AP_CONN_CLOSE)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm && r->server->keep_alive_max
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && !left) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->connection->keepalives++;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->connection->keepalive = AP_CONN_CLOSE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
c57161db43fe4cf5a62758d7d0834675e59cad0astoddardAP_DECLARE(int) ap_meets_conditions(request_rec *r)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *etag;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *if_match, *if_modified_since, *if_unmodified, *if_nonematch;
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard apr_time_t tmp_time;
ec727afb817df0e5202135278c0d2902923cc980stoddard apr_int64_t mtime;
ec727afb817df0e5202135278c0d2902923cc980stoddard int not_modified = 0;
ec727afb817df0e5202135278c0d2902923cc980stoddard
ec727afb817df0e5202135278c0d2902923cc980stoddard /* Check for conditional requests --- note that we only want to do
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * this if we are successful so far and we are not processing a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * subrequest or an ErrorDocument.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * The order of the checks is important, since ETag checks are supposed
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * to be more accurate than checks relative to the modification time.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * However, not all documents are guaranteed to *have* ETags, and some
0942697a9b5de44865676345a3828741c827efe6rbb * might have Last-Modified values w/o ETags, so this gets a little
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * complicated.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_is_HTTP_SUCCESS(r->status) || r->no_local_copy) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb return OK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding etag = apr_table_get(r->headers_out, "ETag");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* All of our comparisons must be in seconds, because that's the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * highest time resolution the HTTP specification allows.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XXX: we should define a "time unset" constant */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding tmp_time = ((r->mtime != 0) ? r->mtime : apr_time_now());
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding mtime = apr_time_sec(tmp_time);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* If an If-Match request-header field was given
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AND the field value is not "*" (meaning match anything)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AND if our strong ETag does not match any entity tag in that field,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * respond with a status of 412 (Precondition Failed).
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb if ((if_match = apr_table_get(r->headers_in, "If-Match")) != NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (if_match[0] != '*'
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard && (etag == NULL || etag[0] == 'W'
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm || !ap_find_list_item(r->pool, if_match, etag))) {
40303323ae9960bd38a0f03d2c10e897a7badd88rbb return HTTP_PRECONDITION_FAILED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
0942697a9b5de44865676345a3828741c827efe6rbb else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Else if a valid If-Unmodified-Since request-header field was given
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * AND the requested resource has been modified since the time
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * specified in this field, then the server MUST
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * respond with a status of 412 (Precondition Failed).
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if_unmodified = apr_table_get(r->headers_in, "If-Unmodified-Since");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (if_unmodified != NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_time_t ius = apr_date_parse_http(if_unmodified);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((ius != APR_DATE_BAD) && (mtime > apr_time_sec(ius))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return HTTP_PRECONDITION_FAILED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* If an If-None-Match request-header field was given
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AND the field value is "*" (meaning match anything)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * OR our ETag matches any of the entity tags in that field, fail.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If the request method was GET or HEAD, failure means the server
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * SHOULD respond with a 304 (Not Modified) response.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * For all other request methods, failure means the server MUST
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * respond with a status of 412 (Precondition Failed).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
2b484455736f4c30447aa852764f53282cbeb5ddrbb * GET or HEAD allow weak etag comparison, all other methods require
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * strong comparison. We can only use weak if it's not a range request.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if_nonematch = apr_table_get(r->headers_in, "If-None-Match");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (if_nonematch != NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->method_number == M_GET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (if_nonematch[0] == '*') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding not_modified = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (etag != NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (apr_table_get(r->headers_in, "Range")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding not_modified = etag[0] != 'W'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && ap_find_list_item(r->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if_nonematch, etag);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding not_modified = ap_find_list_item(r->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if_nonematch, etag);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (if_nonematch[0] == '*'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || (etag != NULL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && ap_find_list_item(r->pool, if_nonematch, etag))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return HTTP_PRECONDITION_FAILED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2b484455736f4c30447aa852764f53282cbeb5ddrbb
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet /* If a valid If-Modified-Since request-header field was given
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * AND it is a GET or HEAD request
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * AND the requested resource has not been modified since the time
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * specified in this field, then the server MUST
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * respond with a status of 304 (Not Modified).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * A date later than the server's current request time is invalid.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->method_number == M_GET
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (not_modified || !if_nonematch)
2b484455736f4c30447aa852764f53282cbeb5ddrbb && (if_modified_since =
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_get(r->headers_in,
2b484455736f4c30447aa852764f53282cbeb5ddrbb "If-Modified-Since")) != NULL) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb apr_time_t ims_time;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int64_t ims, reqtime;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ims_time = apr_date_parse_http(if_modified_since);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ims = apr_time_sec(ims_time);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding reqtime = apr_time_sec(r->request_time);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding not_modified = ims >= mtime && ims <= reqtime;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (not_modified) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return HTTP_NOT_MODIFIED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return OK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/**
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Singleton registry of additional methods. This maps new method names
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * such as "MYGET" to methnums, which are int offsets into bitmasks.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * This follows the same technique as standard M_GET, M_POST, etc. These
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are dynamically assigned when modules are loaded and <Limit GET MYGET>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * directives are processed.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
fd47393e4c08a1515601cb1f1e8deddf4163e858martinstatic apr_hash_t *methods_registry = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int cur_method_number = METHOD_NUMBER_FIRST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* internal function to register one method/number pair */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void register_one_method(apr_pool_t *p, const char *methname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int methnum)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int *pnum = apr_palloc(p, sizeof(*pnum));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *pnum = methnum;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb apr_hash_set(methods_registry, methname, APR_HASH_KEY_STRING, pnum);
7041bead13293c6a2e47ae1babc35f2da1d6a749trawick}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* This internal function is used to clear the method registry
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and reset the cur_method_number counter.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic apr_status_t ap_method_registry_destroy(void *notused)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding methods_registry = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding cur_method_number = METHOD_NUMBER_FIRST;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return APR_SUCCESS;
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe}
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe
a1de70bda57b72d8cc6b47ea744e0973ed424f56wroweAP_DECLARE(void) ap_method_registry_init(apr_pool_t *p)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm methods_registry = apr_hash_make(p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_pool_cleanup_register(p, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_method_registry_destroy,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_pool_cleanup_null);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* put all the standard methods into the registry hash to ease the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding mapping operations between name and number */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "GET", M_GET);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "PUT", M_PUT);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "POST", M_POST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm register_one_method(p, "DELETE", M_DELETE);
0942697a9b5de44865676345a3828741c827efe6rbb register_one_method(p, "CONNECT", M_CONNECT);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "OPTIONS", M_OPTIONS);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "TRACE", M_TRACE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "PATCH", M_PATCH);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "PROPFIND", M_PROPFIND);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "PROPPATCH", M_PROPPATCH);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "MKCOL", M_MKCOL);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "COPY", M_COPY);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "MOVE", M_MOVE);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "LOCK", M_LOCK);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm register_one_method(p, "UNLOCK", M_UNLOCK);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "VERSION-CONTROL", M_VERSION_CONTROL);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "CHECKOUT", M_CHECKOUT);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "UNCHECKOUT", M_UNCHECKOUT);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "CHECKIN", M_CHECKIN);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "UPDATE", M_UPDATE);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb register_one_method(p, "LABEL", M_LABEL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "REPORT", M_REPORT);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "MKWORKSPACE", M_MKWORKSPACE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "MKACTIVITY", M_MKACTIVITY);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, "BASELINE-CONTROL", M_BASELINE_CONTROL);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm register_one_method(p, "MERGE", M_MERGE);
0942697a9b5de44865676345a3828741c827efe6rbb}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int *methnum;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (methods_registry == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_method_registry_init(p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (methname == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return M_INVALID;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Check if the method was previously registered. If it was
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * return the associated method number.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm methnum = (int *)apr_hash_get(methods_registry, methname,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm APR_HASH_KEY_STRING);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (methnum != NULL)
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim return *methnum;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cur_method_number > METHOD_NUMBER_LAST) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* The method registry has run out of dynamically
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * assignable method numbers. Log this and return M_INVALID.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_perror(APLOG_MARK, APLOG_ERR, 0, p,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "Maximum new request methods %d reached while "
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "registering method %s.",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding METHOD_NUMBER_LAST, methname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return M_INVALID;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding register_one_method(p, methname, cur_method_number);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return cur_method_number++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define UNKNOWN_METHOD (-1)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
061c3874622b67beff724876b9bd1b1f291f2eaafieldingstatic int lookup_builtin_method(const char *method, apr_size_t len)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Note: the following code was generated by the "shilka" tool from
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding the "cocom" parsing/compilation toolkit. It is an optimized lookup
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding based on analysis of the input keywords. Postprocessing was done
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding on the shilka output, but the basic structure and analysis is
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding from there. Should new HTTP methods be added, then manual insertion
0942697a9b5de44865676345a3828741c827efe6rbb into this code is fine, or simply re-running the shilka tool on
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm the appropriate input. */
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb /* Note: it is also quite reasonable to just use our method_registry,
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb but I'm assuming (probably incorrectly) we want more speed here
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (based on the optimizations the previous code was doing). */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm switch (len)
cf5ace98ead10d803fda70674cb4dda30fddb832trawick {
cf5ace98ead10d803fda70674cb4dda30fddb832trawick case 3:
cf5ace98ead10d803fda70674cb4dda30fddb832trawick switch (method[0])
cf5ace98ead10d803fda70674cb4dda30fddb832trawick {
2b484455736f4c30447aa852764f53282cbeb5ddrbb case 'P':
2b484455736f4c30447aa852764f53282cbeb5ddrbb return (method[1] == 'U'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[2] == 'T'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_PUT : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case 'G':
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return (method[1] == 'E'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[2] == 'T'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_GET : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding default:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return UNKNOWN_METHOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet case 4:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm switch (method[0])
2b484455736f4c30447aa852764f53282cbeb5ddrbb {
2b484455736f4c30447aa852764f53282cbeb5ddrbb case 'H':
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet return (method[1] == 'E'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[2] == 'A'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[3] == 'D'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_GET : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'P':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (method[1] == 'O'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[2] == 'S'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[3] == 'T'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_POST : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'M':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (method[1] == 'O'
aa811cad2eb3fc01d17a5c8eba274b915ab8cd20manoj && method[2] == 'V'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[3] == 'E'
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe ? M_MOVE : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'L':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (method[1] == 'O'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && method[2] == 'C'
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && method[3] == 'K'
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ? M_LOCK : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case 'C':
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return (method[1] == 'O'
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && method[2] == 'P'
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && method[3] == 'Y'
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ? M_COPY : UNKNOWN_METHOD);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb default:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return UNKNOWN_METHOD;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
e4c4fcc82268e0192db234c74a6db784b879fffdrbb
e4c4fcc82268e0192db234c74a6db784b879fffdrbb case 5:
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb switch (method[2])
2b484455736f4c30447aa852764f53282cbeb5ddrbb {
e4c4fcc82268e0192db234c74a6db784b879fffdrbb case 'T':
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return (memcmp(method, "PATCH", 5) == 0
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ? M_PATCH : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'R':
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb return (memcmp(method, "MERGE", 5) == 0
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ? M_MERGE : UNKNOWN_METHOD);
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case 'C':
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb return (memcmp(method, "MKCOL", 5) == 0
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ? M_MKCOL : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case 'B':
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return (memcmp(method, "LABEL", 5) == 0
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ? M_LABEL : UNKNOWN_METHOD);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb case 'A':
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb return (memcmp(method, "TRACE", 5) == 0
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb ? M_TRACE : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm default:
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb return UNKNOWN_METHOD;
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb }
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard
f17e3ffa43ed4f41d984925d22eb9f8139fcbf1dstoddard case 6:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm switch (method[0])
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb case 'U':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding switch (method[5])
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'K':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "UNLOCK", 6) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_UNLOCK : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'E':
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe return (memcmp(method, "UPDATE", 6) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_UPDATE : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding default:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return UNKNOWN_METHOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'R':
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb return (memcmp(method, "REPORT", 6) == 0
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb ? M_REPORT : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case 'D':
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb return (memcmp(method, "DELETE", 6) == 0
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb ? M_DELETE : UNKNOWN_METHOD);
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb default:
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb return UNKNOWN_METHOD;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb }
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb case 7:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm switch (method[1])
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'P':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "OPTIONS", 7) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_OPTIONS : UNKNOWN_METHOD);
e4c4fcc82268e0192db234c74a6db784b879fffdrbb case 'O':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "CONNECT", 7) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_CONNECT : UNKNOWN_METHOD);
e4c4fcc82268e0192db234c74a6db784b879fffdrbb case 'H':
2b484455736f4c30447aa852764f53282cbeb5ddrbb return (memcmp(method, "CHECKIN", 7) == 0
2b484455736f4c30447aa852764f53282cbeb5ddrbb ? M_CHECKIN : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm default:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return UNKNOWN_METHOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case 8:
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb switch (method[0])
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'P':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "PROPFIND", 8) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_PROPFIND : UNKNOWN_METHOD);
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case 'C':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "CHECKOUT", 8) == 0
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ? M_CHECKOUT : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm default:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return UNKNOWN_METHOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case 9:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "PROPPATCH", 9) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_PROPPATCH : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 10:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding switch (method[0])
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 'U':
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "UNCHECKOUT", 10) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_UNCHECKOUT : UNKNOWN_METHOD);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb case 'M':
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return (memcmp(method, "MKACTIVITY", 10) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_MKACTIVITY : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm default:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return UNKNOWN_METHOD;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 11:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "MKWORKSPACE", 11) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_MKWORKSPACE : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case 15:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (memcmp(method, "VERSION-CONTROL", 15) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_VERSION_CONTROL : UNKNOWN_METHOD);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case 16:
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj return (memcmp(method, "BASELINE-CONTROL", 16) == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ? M_BASELINE_CONTROL : UNKNOWN_METHOD);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm default:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return UNKNOWN_METHOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* NOTREACHED */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb/* Get the method number associated with the given string, assumed to
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * contain an HTTP method. Returns M_INVALID if not recognized.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This is the first step toward placing method names in a configurable
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * list. Hopefully it (and other routines) can eventually be moved to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * something like a mod_http_methods.c, complete with config stuff.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_DECLARE(int) ap_method_number_of(const char *method)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int len = strlen(method);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int which = lookup_builtin_method(method, len);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (which != UNKNOWN_METHOD)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return which;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* check if the method has been dynamically registered */
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if (methods_registry != NULL) {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb int *methnum = apr_hash_get(methods_registry, method, len);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (methnum != NULL) {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb return *methnum;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return M_INVALID;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Turn a known method number into a name.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbAP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb apr_hash_index_t *hi = apr_hash_first(p, methods_registry);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* scan through the hash table, looking for a value that matches
2b484455736f4c30447aa852764f53282cbeb5ddrbb the provided method number. */
2b484455736f4c30447aa852764f53282cbeb5ddrbb for (; hi; hi = apr_hash_next(hi)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const void *key;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding void *val;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_hash_this(hi, &key, NULL, &val);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*(int *)val == methnum)
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb return key;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* it wasn't found in the hash */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb/* The index is found by its offset from the x00 code of each level.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Although this is fast, it will need to be replaced if some nutcase
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * decides to define a high-numbered code before the lower numbers.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If that sad event occurs, replace the code below with a linear search
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbbAP_DECLARE(int) ap_index_of_response(int status)
{
static int shortcut[6] = {0, LEVEL_200, LEVEL_300, LEVEL_400,
LEVEL_500, RESPONSE_CODES};
int i, pos;
if (status < 100) { /* Below 100 is illegal for HTTP status */
return LEVEL_500;
}
for (i = 0; i < 5; i++) {
status -= 100;
if (status < 100) {
pos = (status + shortcut[i]);
if (pos < shortcut[i + 1]) {
return pos;
}
else {
return LEVEL_500; /* status unknown (falls in gap) */
}
}
}
return LEVEL_500; /* 600 or above is also illegal */
}
AP_DECLARE(const char *) ap_get_status_line(int status)
{
return status_lines[ap_index_of_response(status)];
}
/* Build the Allow field-value from the request handler method mask.
* Note that we always allow TRACE, since it is handled below.
*/
static char *make_allow(request_rec *r)
{
char *list;
apr_int64_t mask;
apr_array_header_t *allow = apr_array_make(r->pool, 10, sizeof(char *));
apr_hash_index_t *hi = apr_hash_first(r->pool, methods_registry);
/* For TRACE below */
core_server_config *conf =
ap_get_module_config(r->server->module_config, &core_module);
mask = r->allowed_methods->method_mask;
for (; hi; hi = apr_hash_next(hi)) {
const void *key;
void *val;
apr_hash_this(hi, &key, NULL, &val);
if ((mask & (AP_METHOD_BIT << *(int *)val)) != 0) {
*(const char **)apr_array_push(allow) = key;
/* the M_GET method actually refers to two methods */
if (*(int *)val == M_GET)
*(const char **)apr_array_push(allow) = "HEAD";
}
}
/* TRACE is tested on a per-server basis */
if (conf->trace_enable != AP_TRACE_DISABLE)
*(const char **)apr_array_push(allow) = "TRACE";
list = apr_array_pstrcat(r->pool, allow, ',');
/* ### this is rather annoying. we should enforce registration of
### these methods */
if ((mask & (AP_METHOD_BIT << M_INVALID))
&& (r->allowed_methods->method_list != NULL)
&& (r->allowed_methods->method_list->nelts != 0)) {
int i;
char **xmethod = (char **) r->allowed_methods->method_list->elts;
/*
* Append all of the elements of r->allowed_methods->method_list
*/
for (i = 0; i < r->allowed_methods->method_list->nelts; ++i) {
list = apr_pstrcat(r->pool, list, ",", xmethod[i], NULL);
}
}
return list;
}
AP_DECLARE(int) ap_send_http_options(request_rec *r)
{
if (r->assbackwards) {
return DECLINED;
}
apr_table_setn(r->headers_out, "Allow", make_allow(r));
/* the request finalization will send an EOS, which will flush all
* the headers out (including the Allow header)
*/
return OK;
}
AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct)
{
if (!ct) {
r->content_type = NULL;
}
else if (!r->content_type || strcmp(r->content_type, ct)) {
r->content_type = ct;
/* Insert filters requested by the AddOutputFiltersByType
* configuration directive. Content-type filters must be
* inserted after the content handlers have run because
* only then, do we reliably know the content-type.
*/
ap_add_output_filters_by_type(r);
}
}
static const char *add_optional_notes(request_rec *r,
const char *prefix,
const char *key,
const char *suffix)
{
const char *notes, *result;
if ((notes = apr_table_get(r->notes, key)) == NULL) {
result = apr_pstrcat(r->pool, prefix, suffix, NULL);
}
else {
result = apr_pstrcat(r->pool, prefix, notes, suffix, NULL);
}
return result;
}
/* construct and return the default error message for a given
* HTTP defined error code
*/
static const char *get_canned_error_string(int status,
request_rec *r,
const char *location)
{
apr_pool_t *p = r->pool;
const char *error_notes, *h1, *s1;
switch (status) {
case HTTP_MOVED_PERMANENTLY:
case HTTP_MOVED_TEMPORARILY:
case HTTP_TEMPORARY_REDIRECT:
return(apr_pstrcat(p,
"<p>The document has moved <a href=\"",
ap_escape_html(r->pool, location),
"\">here</a>.</p>\n",
NULL));
case HTTP_SEE_OTHER:
return(apr_pstrcat(p,
"<p>The answer to your request is located "
"<a href=\"",
ap_escape_html(r->pool, location),
"\">here</a>.</p>\n",
NULL));
case HTTP_USE_PROXY:
return(apr_pstrcat(p,
"<p>This resource is only accessible "
"through the proxy\n",
ap_escape_html(r->pool, location),
"<br />\nYou will need to configure "
"your client to use that proxy.</p>\n",
NULL));
case HTTP_PROXY_AUTHENTICATION_REQUIRED:
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:
return(apr_pstrcat(p,
"<p>You don't have permission to access ",
ap_escape_html(r->pool, r->uri),
"\non this server.</p>\n",
NULL));
case HTTP_NOT_FOUND:
return(apr_pstrcat(p,
"<p>The requested URL ",
ap_escape_html(r->pool, r->uri),
" was not found on this server.</p>\n",
NULL));
case HTTP_METHOD_NOT_ALLOWED:
return(apr_pstrcat(p,
"<p>The requested method ",
ap_escape_html(r->pool, r->method),
" is not allowed for the URL ",
ap_escape_html(r->pool, r->uri),
".</p>\n",
NULL));
case HTTP_NOT_ACCEPTABLE:
s1 = apr_pstrcat(p,
"<p>An appropriate representation of the "
"requested resource ",
ap_escape_html(r->pool, r->uri),
" could not be found on this server.</p>\n",
NULL);
return(add_optional_notes(r, s1, "variant-list", ""));
case HTTP_MULTIPLE_CHOICES:
return(add_optional_notes(r, "", "variant-list", ""));
case HTTP_LENGTH_REQUIRED:
s1 = apr_pstrcat(p,
"<p>A request of the requested method ",
ap_escape_html(r->pool, r->method),
" requires a valid Content-length.<br />\n",
NULL);
return(add_optional_notes(r, s1, "error-notes", "</p>\n"));
case HTTP_PRECONDITION_FAILED:
return(apr_pstrcat(p,
"<p>The precondition on the request "
"for the URL ",
ap_escape_html(r->pool, r->uri),
" evaluated to false.</p>\n",
NULL));
case HTTP_NOT_IMPLEMENTED:
s1 = apr_pstrcat(p,
"<p>",
ap_escape_html(r->pool, r->method), " to ",
ap_escape_html(r->pool, r->uri),
" not supported.<br />\n",
NULL);
return(add_optional_notes(r, s1, "error-notes", "</p>\n"));
case HTTP_BAD_GATEWAY:
s1 = "<p>The proxy server received an invalid" CRLF
"response from an upstream server.<br />" CRLF;
return(add_optional_notes(r, s1, "error-notes", "</p>\n"));
case HTTP_VARIANT_ALSO_VARIES:
return(apr_pstrcat(p,
"<p>A variant for the requested "
"resource\n<pre>\n",
ap_escape_html(r->pool, r->uri),
"\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 />",
ap_escape_html(r->pool, r->uri),
"<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));
case HTTP_REQUEST_ENTITY_TOO_LARGE:
return(apr_pstrcat(p,
"The requested resource<br />",
ap_escape_html(r->pool, r->uri), "<br />\n",
"does not allow request data with ",
ap_escape_html(r->pool, r->method),
" requests, or the amount of data provided in\n"
"the request exceeds the capacity limit.\n",
NULL));
case HTTP_REQUEST_URI_TOO_LARGE:
s1 = "<p>The requested URL's length exceeds the capacity\n"
"limit for this server.<br />\n";
return(add_optional_notes(r, s1, "error-notes", "</p>\n"));
case HTTP_UNSUPPORTED_MEDIA_TYPE:
return("<p>The supplied request data is not in a format\n"
"acceptable for processing by this resource.</p>\n");
case HTTP_RANGE_NOT_SATISFIABLE:
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:
return(apr_pstrcat(p,
"<p>The expectation given in the Expect "
"request-header"
"\nfield could not be met by this server.</p>\n"
"<p>The client sent<pre>\n Expect: ",
ap_escape_html(r->pool, apr_table_get(r->headers_in, "Expect")),
"\n</pre>\n"
"but we only allow the 100-continue "
"expectation.</p>\n",
NULL));
case HTTP_UNPROCESSABLE_ENTITY:
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");
case HTTP_INSUFFICIENT_STORAGE:
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_NOT_EXTENDED:
return("<p>A mandatory extension policy in the request is not\n"
"accepted by the server for this resource.</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.)
*/
if (((error_notes = apr_table_get(r->notes,
"error-notes")) != NULL)
&& (h1 = apr_table_get(r->notes, "verbose-error-to")) != NULL
&& (strcmp(h1, "*") == 0)) {
return(apr_pstrcat(p, error_notes, "<p />\n", 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,\n ",
ap_escape_html(r->pool,
r->server->server_admin),
" and inform them of the time the "
"error occurred,\n"
"and anything you might have done that "
"may have\n"
"caused the 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.
*/
AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error)
{
int status = r->status;
int idx = ap_index_of_response(status);
char *custom_response;
const char *location = apr_table_get(r->headers_out, "Location");
/* 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;
ap_run_insert_error_filter(r);
/*
* 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.
*/
if (location == NULL) {
location = apr_table_get(r->err_headers_out, "Location");
}
/* 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) {
ap_finalize_request_protocol(r);
return;
}
if (status == HTTP_NO_CONTENT) {
ap_finalize_request_protocol(r);
return;
}
if (!r->assbackwards) {
apr_table_t *tmp = r->headers_out;
/* 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;
apr_table_clear(r->err_headers_out);
if (ap_is_HTTP_REDIRECT(status) || (status == HTTP_CREATED)) {
if ((location != NULL) && *location) {
apr_table_setn(r->headers_out, "Location", location);
}
else {
location = ""; /* avoids coredump when printing, below */
}
}
r->content_languages = NULL;
r->content_encoding = NULL;
r->clength = 0;
if (apr_table_get(r->subprocess_env,
"suppress-error-charset") != NULL) {
core_request_config *request_conf =
ap_get_module_config(r->request_config, &core_module);
request_conf->suppress_charset = 1; /* avoid adding default
* 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)) {
apr_table_setn(r->headers_out, "Allow", make_allow(r));
}
if (r->header_only) {
ap_finalize_request_protocol(r);
return;
}
}
if ((custom_response = ap_response_code_string(r, idx))) {
/*
* 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] == '\"') {
ap_rputs(custom_response + 1, r);
ap_finalize_request_protocol(r);
return;
}
}
{
const char *title = status_lines[idx];
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;
int len = strlen(r->status_line);
if (len >= 3
&& apr_strtoi64(r->status_line, &end, 10) == r->status
&& (end - 3) == r->status_line
&& (len < 4 || apr_isspace(r->status_line[3]))
&& (len < 5 || apr_isalnum(r->status_line[4]))) {
/* 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) {
r->status_line = apr_pstrcat(r->pool, r->status_line, " Unknown Reason", NULL);
} else if (len == 4) {
r->status_line = apr_pstrcat(r->pool, r->status_line, "Unknown Reason", NULL);
}
title = r->status_line;
}
}
/* folks decided they didn't want the error code in the H1 text */
h1 = &title[4];
/* can't count on a charset filter being in place here,
* so do ebcdic->ascii translation explicitly (if needed)
*/
ap_rvputs_proto_in_ascii(r,
DOCTYPE_HTML_2_0
"<html><head>\n<title>", title,
"</title>\n</head><body>\n<h1>", h1, "</h1>\n",
NULL);
ap_rvputs_proto_in_ascii(r,
get_canned_error_string(status, r, location),
NULL);
if (recursive_error) {
ap_rvputs_proto_in_ascii(r, "<p>Additionally, a ",
status_lines[ap_index_of_response(recursive_error)],
"\nerror was encountered while trying to use an "
"ErrorDocument to handle the request.</p>\n", NULL);
}
ap_rvputs_proto_in_ascii(r, ap_psignature("<hr>\n", r), NULL);
ap_rvputs_proto_in_ascii(r, "</body></html>\n", NULL);
}
ap_finalize_request_protocol(r);
}
/*
* Create a new method list with the specified number of preallocated
* extension slots.
*/
AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts)
{
ap_method_list_t *ml;
ml = (ap_method_list_t *) apr_palloc(p, sizeof(ap_method_list_t));
ml->method_mask = 0;
ml->method_list = apr_array_make(p, nelts, sizeof(char *));
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!).
*/
AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
ap_method_list_t *src)
{
int i;
char **imethods;
char **omethods;
dest->method_mask = src->method_mask;
imethods = (char **) src->method_list->elts;
for (i = 0; i < src->method_list->nelts; ++i) {
omethods = (char **) apr_array_push(dest->method_list);
*omethods = apr_pstrdup(dest->method_list->pool, imethods[i]);
}
}
/*
* Return true if the specified HTTP method is in the provided
* method list.
*/
AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method)
{
int methnum;
int i;
char **methods;
/*
* If it's one of our known methods, use the shortcut and check the
* bitmask.
*/
methnum = ap_method_number_of(method);
if (methnum != M_INVALID) {
return !!(l->method_mask & (AP_METHOD_BIT << methnum));
}
/*
* Otherwise, see if the method name is in the array or string names
*/
if ((l->method_list == NULL) || (l->method_list->nelts == 0)) {
return 0;
}
methods = (char **)l->method_list->elts;
for (i = 0; i < l->method_list->nelts; ++i) {
if (strcmp(method, methods[i]) == 0) {
return 1;
}
}
return 0;
}
/*
* Add the specified method to a method list (if it isn't already there).
*/
AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method)
{
int methnum;
int i;
const char **xmethod;
char **methods;
/*
* If it's one of our known methods, use the shortcut and use the
* bitmask.
*/
methnum = ap_method_number_of(method);
l->method_mask |= (AP_METHOD_BIT << methnum);
if (methnum != M_INVALID) {
return;
}
/*
* Otherwise, see if the method name is in the array of string names.
*/
if (l->method_list->nelts != 0) {
methods = (char **)l->method_list->elts;
for (i = 0; i < l->method_list->nelts; ++i) {
if (strcmp(method, methods[i]) == 0) {
return;
}
}
}
xmethod = (const char **) apr_array_push(l->method_list);
*xmethod = method;
}
/*
* Remove the specified method from a method list.
*/
AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l,
const char *method)
{
int methnum;
char **methods;
/*
* If it's a known methods, either builtin or registered
* by a module, use the bitmask.
*/
methnum = ap_method_number_of(method);
l->method_mask |= ~(AP_METHOD_BIT << methnum);
if (methnum != M_INVALID) {
return;
}
/*
* Otherwise, see if the method name is in the array of string names.
*/
if (l->method_list->nelts != 0) {
register int i, j, k;
methods = (char **)l->method_list->elts;
for (i = 0; i < l->method_list->nelts; ) {
if (strcmp(method, methods[i]) == 0) {
for (j = i, k = i + 1; k < l->method_list->nelts; ++j, ++k) {
methods[j] = methods[k];
}
--l->method_list->nelts;
}
else {
++i;
}
}
}
}
/*
* Reset a method list to be completely empty.
*/
AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l)
{
l->method_mask = 0;
l->method_list->nelts = 0;
}