aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-03 23:09:11 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-03 23:09:11 +0300
commit69580ef09cfb0f41fa50d3252f4a83cfb7f153b5 (patch)
tree87f2c4c07719f30698a0f34c61020c395181c7d3 /server.py
parentprune obsolete entry from .gitignore (diff)
downloadlinux-status-69580ef09cfb0f41fa50d3252f4a83cfb7f153b5.tar.gz
linux-status-69580ef09cfb0f41fa50d3252f4a83cfb7f153b5.zip
add server.py
It runs a web server and imports the request handling classes from get.py directly, hence eliminating the performance culprit (which was the `import` processing for each request).
Diffstat (limited to '')
-rwxr-xr-xserver.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/server.py b/server.py
new file mode 100755
index 0000000..9533be7
--- /dev/null
+++ b/server.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2021 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "linux-status" project.
+# For details, see https://github.com/egor-tensin/linux-status.
+# Distributed under the MIT License.
+
+import http.server
+
+from get import Request
+
+
+class RequestHandler(http.server.CGIHTTPRequestHandler):
+ def do_GET(self):
+ try:
+ request = Request.from_http_path(self.path)
+ except ValueError:
+ return super().do_GET()
+ request.process().write_as_request_handler(self)
+
+
+def main():
+ addr = ('', 18101)
+ httpd = http.server.ThreadingHTTPServer(addr, RequestHandler)
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ print('\nKeyboard interrupt received, exiting...')
+
+
+if __name__ == '__main__':
+ main()