const int translateRequest()

in modules/server/mod-eval.hpp [1061:1112]


const int translateRequest(request_rec* const r, const list<value>& rpath, const list<value>& vpath, const list<value>& refs, const list<value>& svcs, const list<value>& impls) {
    debug(vpath, "modeval::translateRequest::vpath");
    debug(rpath, "modeval::translateRequest::rpath");
    const string prefix = isNull(rpath)? emptyStringValue : car(rpath);

    // Translate a component request
    if ((prefix == string("components") || prefix == string("c")) && translateComponent(r, rpath, vpath, impls) == OK)
        return proceedToHandler(r, OK);

    // Translate a component reference request
    if ((prefix == string("references") || prefix == string("r")) && translateReference(r, rpath, vpath, refs, impls) == OK)
        return proceedToHandler(r, OK);

    // Attempt to translate the request to a service request
    if (translateService(r, rpath, vpath, svcs, impls) == OK)
        return proceedToHandler(r, OK);

    // Attempt to map a request targeting the main host to an actual file
    if (isNull(vpath)) {
        const failable<request_rec*> fnr = httpd::internalSubRequest(r->uri, r);
        if (!hasContent(fnr))
            return rcode(fnr);
        request_rec* const nr = content(fnr);
        nr->uri = r->filename;
        const int tr = ap_core_translate(nr);
        if (tr != OK)
            return tr;
        if (ap_directory_walk(nr) == OK && ap_file_walk(nr) == OK && nr->finfo.filetype != APR_NOFILE) {

            // Found the target file, let the default handler serve it
            debug(nr->filename, "modeval::translateRequest::file");
            return DECLINED;
        }
    } else {

        // Make sure a document root request ends with a '/' using
        // an external redirect
        if (isNull(rpath) && r->uri[strlen(r->uri) - 1] != '/') {
            const string target = string(r->uri) + string("/") + (r->args != NULL? string("?") + string(r->args) : emptyString);
            debug(target, "modeval::translateRequest::location");
            return proceedToHandler(r, httpd::externalRedirect(target, r));
        }

        // If the request didn't match a service, reference or component,
        // redirect it to / v / app / path. This will allow mapping to
        // the actual app resource using HTTPD aliases.
        debug(true, "modeval::translateRequest::valias");
        return proceedToHandler(r, OK, true, rpath, vpath, impls);
    }

    return HTTP_NOT_FOUND;
}