Beispiel #1
0
        bool isknowntype(String uri)
        {
            String[] ignored_exts = { ".css", ".js", ".html", ".htm", ".png", ".bmp", ".jpg", ".jpeg", ".gif" };

            String strExt = CFilePath.getExtension(uri).ToLower();

            return(find_in_string_array(strExt, ignored_exts));
        }
Beispiel #2
0
        String getIndex(String path)
        {
            String[] index_files = { "index_erb.rb", "index.html", "index.htm", "index.php", "index.cgi" };

            if (CFilePath.getExtension(path).Length == 0)
            {
                return(CFilePath.join(path, index_files[0]));
            }

            String strFileName = CFilePath.getBaseName(path);

            return(find_in_string_array(strFileName, index_files) ? path : "");
        }
Beispiel #3
0
        IDictionary processIndex(CRoute route, String method, String uri, Dictionary <String, String> headers, String query, String body)
        {
            Object rhoResp = new Dictionary <String, String>();

            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strFilePath;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "404";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Not Found";
                return((IDictionary)rhoResp);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strIndexFile;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "200";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Ok";
                return((IDictionary)rhoResp);
            }

            Object rhoReq = create_request_hash(route, method, uri, query, headers, body);

            rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strRedirectUrl;
                return((IDictionary)rhoResp);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strIndexFile;
            return((IDictionary)rhoResp);
        }
Beispiel #4
0
        String processIndex(CRoute route, String method, String uri, String query, String body)
        {
            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                return(strFilePath);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                return(strIndexFile);
            }

            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strIndexFile);
        }
Beispiel #5
0
        public CResponse decide(String method, String uri, String query, String body)
        {
            if (uri.EndsWith(".gen.html") || (isknowntype(uri) && uri.StartsWith(m_root)))
            {
                return(new CResponse(false));
            }

            if (process_registered(uri))
            {
                return(new CResponse(false));
            }

            CRoute route = new CRoute();

            if (dispatch(uri, route))
            {
                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServe(rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";
                if (route.id.Length > 0)
                {
                    strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
                }

                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strFilePath));
            }

            String fullPath = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                if (!CRhoFile.isResourceFileExist(strIndexFile))
                {
                    String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                    String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                    CRhoFile.recursiveCreateDir(strFilePath);
                    CRhoFile.writeStringToFile(strFilePath, error);
                    return(new CResponse(strFilePath));
                }

                if (CFilePath.getExtension(fullPath).Length > 0)
                {
                    return(new CResponse(strIndexFile));
                }

                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                strIndexFile += ".gen.html";
                CRhoFile.recursiveCreateDir(strIndexFile);
                CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strIndexFile));
            }

            return(new CResponse(false));
        }