From 2f4be29b8284c3c7adb074e6a0353fd8b722dbb6 Mon Sep 17 00:00:00 2001 From: Alexandra Rahlin Date: Fri, 13 Sep 2024 12:40:18 -0500 Subject: [PATCH] Drop --verbose option from server (#46) This option currently only affects outputs to stderr from the file service endpoint, and is largely redundant with what the file server would return to the user anyway. It makes some sense to remove this option so that users don't expect verbose output from the tuber endpoint by enabling it. --- src/server.cpp | 41 ++++------------------------------------- tuber/server.py | 13 ++----------- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 1c0038e..d78dd70 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -24,22 +24,6 @@ namespace fs = std::filesystem; * about symbol visibility here, we follow its lead to squash warnings. */ #define DLL_LOCAL __attribute__((visibility("hidden"))) -/* Verbosity is expressed as a bit mask: - * 0: none (default) - * 1: report unexpected or unusual cases - * 2: very noisy - */ -static enum class Verbose { - NONE = 0, /* default */ - UNEXPECTED = 1, /* report unexected or unusual cases */ - NOISY = 2, /* message onslaught */ -} verbose; - -/* Operators for log levels */ -inline constexpr int operator&(Verbose const& x, Verbose const& y) { - return static_cast(x) & static_cast(y); -} - /* MIME types */ static const std::string MIME_JSON="application/json"; static const std::string MIME_CBOR="application/cbor"; @@ -128,12 +112,8 @@ class DLL_LOCAL file_resource : public http_resource { path /= "index.html"; /* Serve 404 if the resource does not exist, or we couldn't find it */ - if(!fs::is_regular_file(path)) { - if(verbose & Verbose::UNEXPECTED) - std::cerr << "Unable or unwilling to serve missing or non-file resource " << path.string() << '\n'; - + if(!fs::is_regular_file(path)) return std::make_shared("No such file or directory.\n", http::http_utils::http_not_found); - } /* Figure out a MIME type to use */ std::string mime_type = MIME_DEFAULT; @@ -141,10 +121,6 @@ class DLL_LOCAL file_resource : public http_resource { if(it != MIME_TYPES.end()) mime_type = it->second; - if(verbose & Verbose::NOISY) - std::cerr << "Serving " << req.get_path() << " with " << path.string() - << " using MIME type " << mime_type << '\n'; - /* Construct response and return it */ auto response = std::make_shared(path.string(), http::http_utils::http_ok, mime_type); response->with_header(http::http_utils::http_header_cache_control, @@ -163,14 +139,8 @@ static void sigint(int signo) { ws->stop(); } -void run_server(py::object handler, int port=80, const std::string &webroot="/var/www", int max_age=3600, int verbose_level=0) +static void run_server(py::object handler, int port=80, const std::string &webroot="/var/www", int max_age=3600) { - /* - * Parse command-line arguments - */ - - verbose = static_cast(verbose_level); - /* Can only run one server at a time */ if (ws) throw std::runtime_error("Tuber server already running!"); @@ -229,9 +199,6 @@ PYBIND11_MODULE(_tuber_runtime, m) { "webroot : str\n" " Location to serve static content\n" "max_age : int\n" - " Maximum cache residency for static (file) assets\n" - "verbose : int\n" - " Verbosity level (0-2)\n", - py::arg("handler"), py::arg("port")=80, py::arg("webroot")="/var/www/", - py::arg("max_age")=3600, py::arg("verbose")=0); + " Maximum cache residency for static (file) assets\n", + py::arg("handler"), py::arg("port")=80, py::arg("webroot")="/var/www/", py::arg("max_age")=3600); } diff --git a/tuber/server.py b/tuber/server.py index 87a8bfe..9870433 100644 --- a/tuber/server.py +++ b/tuber/server.py @@ -575,7 +575,7 @@ def __call__(self, *args, **kwargs): return self.handle(*args, **kwargs) -def run(registry, json_module="json", port=80, webroot="/var/www/", max_age=3600, validate=False, verbose=0): +def run(registry, json_module="json", port=80, webroot="/var/www/", max_age=3600, validate=False): """ Run tuber server with the given registry. @@ -593,8 +593,6 @@ def run(registry, json_module="json", port=80, webroot="/var/www/", max_age=3600 Maximum cache residency for static (file) assets validate : bool If True, validate incoming and outgoing data packets using jsonschema - verbose : int - Verbosity level (0-2) """ # setup environment os.environ["TUBER_SERVER"] = "1" @@ -609,13 +607,7 @@ def run(registry, json_module="json", port=80, webroot="/var/www/", max_age=3600 handler = RequestHandler(registry, json_module, validate=validate) # run - run_server( - handler, - port=port, - webroot=webroot, - max_age=max_age, - verbose=verbose, - ) + run_server(handler, port=port, webroot=webroot, max_age=max_age) def load_registry(filename): @@ -670,7 +662,6 @@ def main(registry=None): P.add_argument( "--validate", action="store_true", help="Validate incoming and outgoing data packets using jsonschema" ) - P.add_argument("-v", "--verbose", type=int, default=0) args = P.parse_args() # setup environment