static ngx_int_t
ngx_http_index_handler(ngx_http_request_t *r)
{
    u_char                       *p, *name;
    size_t                        len, root, reserve, allocated;
    ngx_int_t                     rc;
    ngx_str_t                     path, uri;
    ngx_uint_t                    i, dir_tested;
    ngx_http_index_t             *index;
    ngx_open_file_info_t          of;
    ngx_http_script_code_pt       code;
    ngx_http_script_engine_t      e;
    ngx_http_core_loc_conf_t     *clcf;
    ngx_http_index_loc_conf_t    *ilcf;
    ngx_http_script_len_code_pt   lcode;
    if (r->uri.data[r->uri.len - 1] != '/') {
        return NGX_DECLINED;
    }
    if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {
        return NGX_DECLINED;
    }
    if (r->zero_in_uri) {
        return NGX_DECLINED;
    }
    ilcf = ngx_http_get_module_loc_conf(r, ngx_http_index_module);
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    allocated = 0;
    root = 0;
    dir_tested = 0;
    name = NULL;
    path.data = NULL;
    index = ilcf->indices->elts;
    for (i = 0; i < ilcf->indices->nelts; i++) {
        if (index[i].lengths == NULL) {
            if (index[i].name.data[0] == '/') {
                return ngx_http_internal_redirect(r, &index[i].name, &r->args);
            }
            reserve = ilcf->max_index_len;
            len = index[i].name.len;
        } else {
            ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
            e.ip = index[i].lengths->elts;
            e.request = r;
            e.flushed = 1;
            len = 1;
            while (*(uintptr_t *) e.ip) {
                lcode = *(ngx_http_script_len_code_pt *) e.ip;
                len += lcode(&e);
            }
            reserve = len + 16;
        }
        if (reserve > allocated) {
            name = ngx_http_map_uri_to_path(r, &path, &root, reserve);
            if (name == NULL) {
                return NGX_ERROR;
            }
            allocated = path.data + path.len - name;
        }
        if (index[i].values == NULL) {
            ngx_memcpy(name, index[i].name.data, index[i].name.len);
            path.len = (name + index[i].name.len - 1) - path.data;
        } else {
            e.ip = index[i].values->elts;
            e.pos = name;
            while (*(uintptr_t *) e.ip) {
                code = *(ngx_http_script_code_pt *) e.ip;
                code((ngx_http_script_engine_t *) &e);
            }
            if (*name == '/') {
                uri.len = len - 1;
                uri.data = name;
                return ngx_http_internal_redirect(r, &uri, &r->args);
            }
            path.len = e.pos - path.data;
            *e.pos = '\0';
        }
        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                       "open index \"%V\"", &path);
        ngx_memzero(&of, sizeof(ngx_open_file_info_t));
        of.directio = clcf->directio;
        of.valid = clcf->open_file_cache_valid;
        of.min_uses = clcf->open_file_cache_min_uses;
        of.errors = clcf->open_file_cache_errors;
        of.events = clcf->open_file_cache_events;
        if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
            != NGX_OK)
        {
            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,
                           ngx_open_file_n " \"%s\" failed", path.data);
            if (of.err == 0) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }
            if (of.err == NGX_ENOTDIR || of.err == NGX_EACCES) {
                return ngx_http_index_error(r, clcf, path.data, of.err);
            }
            if (!dir_tested) {
                rc = ngx_http_index_test_dir(r, clcf, path.data, name - 1);
                if (rc != NGX_OK) {
                    return rc;
                }
                dir_tested = 1;
            }
            if (of.err == NGX_ENOENT) {
                continue;
            }
            ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err,
                          ngx_open_file_n " \"%s\" failed", path.data);
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }
        uri.len = r->uri.len + len - 1;
        if (!clcf->alias) {
            uri.data = path.data + root;
        } else {
            uri.data = ngx_pnalloc(r->pool, uri.len);
            if (uri.data == NULL) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }
            p = ngx_copy(uri.data, r->uri.data, r->uri.len);
            ngx_memcpy(p, name, len - 1);
        }
        return ngx_http_internal_redirect(r, &uri, &r->args);
    }
    return NGX_DECLINED;
}
['static ngx_int_t\nngx_http_index_handler(ngx_http_request_t *r)\n{\n    u_char                       *p, *name;\n    size_t                        len, root, reserve, allocated;\n    ngx_int_t                     rc;\n    ngx_str_t                     path, uri;\n    ngx_uint_t                    i, dir_tested;\n    ngx_http_index_t             *index;\n    ngx_open_file_info_t          of;\n    ngx_http_script_code_pt       code;\n    ngx_http_script_engine_t      e;\n    ngx_http_core_loc_conf_t     *clcf;\n    ngx_http_index_loc_conf_t    *ilcf;\n    ngx_http_script_len_code_pt   lcode;\n    if (r->uri.data[r->uri.len - 1] != \'/\') {\n        return NGX_DECLINED;\n    }\n    if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {\n        return NGX_DECLINED;\n    }\n    if (r->zero_in_uri) {\n        return NGX_DECLINED;\n    }\n    ilcf = ngx_http_get_module_loc_conf(r, ngx_http_index_module);\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    allocated = 0;\n    root = 0;\n    dir_tested = 0;\n    name = NULL;\n    path.data = NULL;\n    index = ilcf->indices->elts;\n    for (i = 0; i < ilcf->indices->nelts; i++) {\n        if (index[i].lengths == NULL) {\n            if (index[i].name.data[0] == \'/\') {\n                return ngx_http_internal_redirect(r, &index[i].name, &r->args);\n            }\n            reserve = ilcf->max_index_len;\n            len = index[i].name.len;\n        } else {\n            ngx_memzero(&e, sizeof(ngx_http_script_engine_t));\n            e.ip = index[i].lengths->elts;\n            e.request = r;\n            e.flushed = 1;\n            len = 1;\n            while (*(uintptr_t *) e.ip) {\n                lcode = *(ngx_http_script_len_code_pt *) e.ip;\n                len += lcode(&e);\n            }\n            reserve = len + 16;\n        }\n        if (reserve > allocated) {\n            name = ngx_http_map_uri_to_path(r, &path, &root, reserve);\n            if (name == NULL) {\n                return NGX_ERROR;\n            }\n            allocated = path.data + path.len - name;\n        }\n        if (index[i].values == NULL) {\n            ngx_memcpy(name, index[i].name.data, index[i].name.len);\n            path.len = (name + index[i].name.len - 1) - path.data;\n        } else {\n            e.ip = index[i].values->elts;\n            e.pos = name;\n            while (*(uintptr_t *) e.ip) {\n                code = *(ngx_http_script_code_pt *) e.ip;\n                code((ngx_http_script_engine_t *) &e);\n            }\n            if (*name == \'/\') {\n                uri.len = len - 1;\n                uri.data = name;\n                return ngx_http_internal_redirect(r, &uri, &r->args);\n            }\n            path.len = e.pos - path.data;\n            *e.pos = \'\\0\';\n        }\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "open index \\"%V\\"", &path);\n        ngx_memzero(&of, sizeof(ngx_open_file_info_t));\n        of.directio = clcf->directio;\n        of.valid = clcf->open_file_cache_valid;\n        of.min_uses = clcf->open_file_cache_min_uses;\n        of.errors = clcf->open_file_cache_errors;\n        of.events = clcf->open_file_cache_events;\n        if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)\n            != NGX_OK)\n        {\n            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,\n                           ngx_open_file_n " \\"%s\\" failed", path.data);\n            if (of.err == 0) {\n                return NGX_HTTP_INTERNAL_SERVER_ERROR;\n            }\n            if (of.err == NGX_ENOTDIR || of.err == NGX_EACCES) {\n                return ngx_http_index_error(r, clcf, path.data, of.err);\n            }\n            if (!dir_tested) {\n                rc = ngx_http_index_test_dir(r, clcf, path.data, name - 1);\n                if (rc != NGX_OK) {\n                    return rc;\n                }\n                dir_tested = 1;\n            }\n            if (of.err == NGX_ENOENT) {\n                continue;\n            }\n            ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err,\n                          ngx_open_file_n " \\"%s\\" failed", path.data);\n            return NGX_HTTP_INTERNAL_SERVER_ERROR;\n        }\n        uri.len = r->uri.len + len - 1;\n        if (!clcf->alias) {\n            uri.data = path.data + root;\n        } else {\n            uri.data = ngx_pnalloc(r->pool, uri.len);\n            if (uri.data == NULL) {\n                return NGX_HTTP_INTERNAL_SERVER_ERROR;\n            }\n            p = ngx_copy(uri.data, r->uri.data, r->uri.len);\n            ngx_memcpy(p, name, len - 1);\n        }\n        return ngx_http_internal_redirect(r, &uri, &r->args);\n    }\n    return NGX_DECLINED;\n}']