diff --git a/examples/cowsay.cgi b/examples/cowsay.cgi new file mode 100755 index 0000000..b75fff9 --- /dev/null +++ b/examples/cowsay.cgi @@ -0,0 +1,38 @@ +#!/usr/local/bin/python3.7 +""" +CGI script that requests user supplied text using the INPUT status, and +pipes it into the `cowsay` program. + + _________________ +< Gemini is cool! > + ----------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || +""" +import os +import subprocess +import sys +import urllib.parse + +query = os.environ["QUERY_STRING"] +if not query: + print("10 Enter your cowsay message") + sys.exit() + +text = urllib.parse.unquote(query) +try: + proc = subprocess.run( + ["/usr/local/bin/cowsay"], + input=text, + capture_output=True, + check=True, + text=True, + ) +except: + print("42 Unexpected Error") +else: + print("20 text/plain") + print(proc.stdout) diff --git a/examples/cgi_debug.cgi b/examples/debug.cgi similarity index 79% rename from examples/cgi_debug.cgi rename to examples/debug.cgi index 3a993de..1d8c794 100755 --- a/examples/cgi_debug.cgi +++ b/examples/debug.cgi @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/local/bin/python3.7 """ This is a demo CGI script that prints a bunch of debug information about the request as an HTML document. Place it in the cgi-bin/ directory of your @@ -6,5 +6,5 @@ server. """ import cgi -print("200 text/html") +print("20 text/html") cgi.test() diff --git a/jetforce.py b/jetforce.py index 8115bba..a2f3b0b 100755 --- a/jetforce.py +++ b/jetforce.py @@ -273,7 +273,7 @@ class StaticDirectoryApplication(JetforceApplication): status_line = out.stdout.readline().strip() status_parts = status_line.split(maxsplit=1) if len(status_parts) != 2 or not status_parts[0].isdecimal(): - return Response(Status.CGI_ERROR, "Script generated invalid response") + return Response(Status.CGI_ERROR, "Unexpected Error") status, meta = status_parts