From 95eeffdd8cc3443add1ce2c739d0c413ac502015 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 11 Apr 2022 10:58:45 +0200 Subject: src: shorter import --- src/app.py | 3 ++- src/server.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app.py b/src/app.py index 5af55af..b0c4672 100755 --- a/src/app.py +++ b/src/app.py @@ -44,6 +44,7 @@ import cgi from collections import namedtuple from concurrent.futures import ThreadPoolExecutor from enum import Enum +from http import HTTPStatus import http.server import json import os @@ -66,7 +67,7 @@ def split_by(xs, sep): class Response: - DEFAULT_STATUS = http.server.HTTPStatus.OK + DEFAULT_STATUS = HTTPStatus.OK @staticmethod def body_from_json(body): diff --git a/src/server.py b/src/server.py index 75723bd..9ffe6f1 100755 --- a/src/server.py +++ b/src/server.py @@ -9,6 +9,7 @@ # custom URLs. See that file for the reasons behind this. import argparse +from http import HTTPStatus import http.server import os import sys @@ -38,7 +39,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): response = request.process() response.write_to_request_handler(self) except: - status = http.server.HTTPStatus.INTERNAL_SERVER_ERROR + status = HTTPStatus.INTERNAL_SERVER_ERROR response = Response(traceback.format_exc(), status) response.write_to_request_handler(self) return -- cgit v1.2.3 From ce5bb34296429bd2401bb51c01522dd0c1bfbf83 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 11 Apr 2022 11:02:59 +0200 Subject: app.py: print HTTP status when CGIing --- src/app.py | 1 + test/test.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app.py b/src/app.py index b0c4672..b83666e 100755 --- a/src/app.py +++ b/src/app.py @@ -90,6 +90,7 @@ class Response: self.write_body_as_cgi_script() def write_headers_as_cgi_script(self): + print(f'{self.status.value} {self.status.phrase}') for name, val in self.headers(): print(f'{name}: {val}') print() diff --git a/test/test.sh b/test/test.sh index 8597a24..3b22039 100755 --- a/test/test.sh +++ b/test/test.sh @@ -147,7 +147,7 @@ run_curl_tests() { } cgi_check_header() { - local expected='Content-Type: text/html; charset=utf-8' + local expected='200 OK' local actual actual="$( head -n 1 -- "$curl_output_file" )" -- cgit v1.2.3 From 1a3a8f1ec191d3811730fd149521abcb2205a018 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 11 Apr 2022 11:36:31 +0200 Subject: support disallowing power requests --- html/index.html | 37 +++++++++++++++++++++++++++++++++++-- src/app.py | 37 ++++++++++++++++++++++++++++++++----- src/server.py | 6 ++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/html/index.html b/html/index.html index 944005c..89882b9 100644 --- a/html/index.html +++ b/html/index.html @@ -61,6 +61,22 @@
+