LCOV - code coverage report
Current view: top level - extra/webserver/webserver/tools - SPWebTools.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 27 92.6 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2024 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "SPWebTools.h"
      24             : #include "SPWebRequestHandler.h"
      25             : #include "SPWebVirtualFile.h"
      26             : #include "SPWebOutput.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::web::tools {
      29             : 
      30          25 : void registerTools(StringView prefix, Host &host) {
      31          25 :         host.addHandler(prefix, RequestHandler::Make<tools::ServerGui>());
      32          25 :         host.addHandler(toString(prefix, config::TOOLS_SHELL), RequestHandler::Make<tools::ShellGui>());
      33          25 :         host.addHandler(toString(prefix, config::TOOLS_ERRORS), RequestHandler::Make<tools::ErrorsGui>());
      34             :         //host.addHandler(toString(prefix, config::TOOLS_DOCS), RequestHandler::Handler<tools::VirtualGui>());
      35          25 :         host.addHandler(toString(prefix, config::TOOLS_HANDLERS), RequestHandler::Make<tools::HandlersGui>());
      36          25 :         host.addHandler(toString(prefix, config::TOOLS_REPORTS), RequestHandler::Make<tools::ReportsGui>());
      37          25 :         host.addWebsocket(toString(prefix, config::TOOLS_SHELL_SOCKET), new tools::ShellSocket(host));
      38             : 
      39          25 :         host.addHandler(toString(prefix, config::TOOLS_AUTH), RequestHandler::Make<tools::AuthHandler>());
      40          25 :         host.addHandler(toString(prefix, config::TOOLS_VIRTUALFS), RequestHandler::Make<tools::VirtualFilesystem>());
      41          25 : }
      42             : 
      43          75 : Status VirtualFilesystem::onTranslateName(Request &rctx) {
      44          75 :         if (rctx.getInfo().method != RequestMethod::Get) {
      45           0 :                 return DECLINED;
      46             :         }
      47             : 
      48          75 :         auto d = VirtualFile::getList();
      49         250 :         for (auto &it : d) {
      50         250 :                 if (_subPath == it.name) {
      51          75 :                         if (_subPath.ends_with(".js")) {
      52          25 :                                 rctx.setContentType("application/javascript");
      53          50 :                         } else if (_subPath.ends_with(".css")) {
      54          25 :                                 rctx.setContentType("text/css");
      55          25 :                         } else if (_subPath.ends_with(".html")) {
      56          25 :                                 rctx.setContentType("text/html;charset=UTF-8");
      57             :                         }
      58             : 
      59          75 :                         if (output::checkCacheHeaders(rctx, getCompileUnixTime(), hash::hash32(it.name.data(), it.name.size()))) {
      60          75 :                                 return HTTP_NOT_MODIFIED;
      61             :                         }
      62             : 
      63          75 :                         rctx << it.content;
      64          75 :                         return DONE;
      65             :                         break;
      66             :                 }
      67             :         }
      68             : 
      69           0 :         return HTTP_NOT_FOUND;
      70             : }
      71             : 
      72             : }

Generated by: LCOV version 1.14