⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http_protocol.c

📁 linux网络服务器工具
💻 C
📖 第 1 页 / 共 4 页
字号:
        if (*(int *)val == methnum)            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]; */AP_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 proxy server did not receive a timely response\n"               "from the upstream server.</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"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -