From fc97ba4ef16256db0cfff3ef61b8827dba45d348 Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 27 Nov 2021 12:49:30 +0100 Subject: [PATCH] smolcgi: add helpers for every defined status code --- smolcgi.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/smolcgi.py b/smolcgi.py index 50af8b9..cc1a9ae 100644 --- a/smolcgi.py +++ b/smolcgi.py @@ -68,15 +68,23 @@ def header(code, meta): print(f"{code} {meta}", end="\r\n") +def success(mime): + header(20, mime) + + def exit_with_header(code, meta): header(code, meta) exit() -def require_input(reason): +def require_input(reason=""): exit_with_header(10, reason) +def require_sensitive_input(reason=""): + exit_with_header(11, reason) + + def redirect_temp(url): exit_with_header(30, url) @@ -85,15 +93,43 @@ def redirect_perm(url): exit_with_header(31, url) -def temp_error(reason): +def temp_error(reason=""): + exit_with_header(40, reason) + + +def server_unavailable(reason=""): + exit_with_header(41, reason) + + +def cgi_error(reason=""): exit_with_header(42, reason) -def not_found(reason="Not found"): +def proxy_error(reason=""): + exit_with_header(43, reason) + + +def slow_down(num_seconds): + exit_with_header(44, num_seconds) + + +def perm_error(reason=""): + exit_with_header(50, reason) + + +def not_found(reason=""): exit_with_header(51, reason) -def bad_request(reason="Bad request"): +def gone(reason=""): + exit_with_header(52, reason) + + +def proxy_request_refused(reason=""): + exit_with_header(53, reason) + + +def bad_request(reason=""): exit_with_header(59, reason) @@ -102,6 +138,14 @@ def require_client_cert(): exit_with_header(60, "You need a certificate to use this app") +def cert_not_authorised(reason=""): + exit_with_header(61, reason) + + +def cert_not_valid(reason=""): + exit_with_header(62, reason) + + def print_env(): globz = globals() for key in cgi_vars: