ngx_int_t
ngx_http_set_exten(ngx_http_request_t *r)
{
    ngx_int_t  i;
    r->exten.len = 0;
    r->exten.data = NULL;
    for (i = r->uri.len - 1; i > 1; i--) {
        if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
            r->exten.len = r->uri.len - i - 1;
            r->exten.data = &r->uri.data[i + 1];
            break;
        } else if (r->uri.data[i] == '/') {
            break;
        }
    }
    return NGX_OK;
}
['void\nngx_http_script_regex_end_code(ngx_http_script_engine_t *e)\n{\n    u_char                            *dst, *src;\n    ngx_http_request_t                *r;\n    ngx_http_script_regex_end_code_t  *code;\n    code = (ngx_http_script_regex_end_code_t *) e->ip;\n    r = e->request;\n    e->quote = 0;\n    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "http script regex end");\n    if (code->redirect) {\n        dst = e->buf.data;\n        src = e->buf.data;\n        ngx_unescape_uri(&dst, &src, e->pos - e->buf.data,\n                         NGX_UNESCAPE_REDIRECT);\n        if (src < e->pos) {\n            dst = ngx_copy(dst, src, e->pos - src);\n        }\n        e->pos = dst;\n        if (code->add_args && r->args.len) {\n            *e->pos++ = (u_char) (code->args ? \'&\' : \'?\');\n            e->pos = ngx_copy(e->pos, r->args.data, r->args.len);\n        }\n        e->buf.len = e->pos - e->buf.data;\n        if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {\n            ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,\n                          "rewritten redirect: \\"%V\\"", &e->buf);\n        }\n        r->headers_out.location = ngx_list_push(&r->headers_out.headers);\n        if (r->headers_out.location == NULL) {\n            e->ip = ngx_http_script_exit;\n            e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;\n            return;\n        }\n        r->headers_out.location->hash = 1;\n        r->headers_out.location->key.len = sizeof("Location") - 1;\n        r->headers_out.location->key.data = (u_char *) "Location";\n        r->headers_out.location->value = e->buf;\n        e->ip += sizeof(ngx_http_script_regex_end_code_t);\n        return;\n    }\n    if (e->args) {\n        e->buf.len = e->args - e->buf.data;\n        if (code->add_args && r->args.len) {\n            *e->pos++ = \'&\';\n            e->pos = ngx_copy(e->pos, r->args.data, r->args.len);\n        }\n        r->args.len = e->pos - e->args;\n        r->args.data = e->args;\n        e->args = NULL;\n    } else {\n        e->buf.len = e->pos - e->buf.data;\n        if (!code->add_args) {\n            r->args.len = 0;\n        }\n    }\n    if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {\n        ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,\n                      "rewritten data: \\"%V\\", args: \\"%V\\"",\n                      &e->buf, &r->args);\n    }\n    if (code->uri) {\n        r->uri = e->buf;\n        if (r->uri.len == 0) {\n            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n                          "the rewritten URI has a zero length");\n            e->ip = ngx_http_script_exit;\n            e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;\n            return;\n        }\n        if (ngx_http_set_exten(r) != NGX_OK) {\n            e->ip = ngx_http_script_exit;\n            e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;\n            return;\n        }\n    }\n    e->ip += sizeof(ngx_http_script_regex_end_code_t);\n}', "ngx_int_t\nngx_http_set_exten(ngx_http_request_t *r)\n{\n    ngx_int_t  i;\n    r->exten.len = 0;\n    r->exten.data = NULL;\n    for (i = r->uri.len - 1; i > 1; i--) {\n        if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n            r->exten.len = r->uri.len - i - 1;\n            r->exten.data = &r->uri.data[i + 1];\n            break;\n        } else if (r->uri.data[i] == '/') {\n            break;\n        }\n    }\n    return NGX_OK;\n}"]