smolcgi: add helpers for every defined status code
This commit is contained in:
parent
989df5a849
commit
fc97ba4ef1
52
smolcgi.py
52
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:
|
||||
|
|
Reference in a new issue