From 82b1ec90dc1abc9600d17f39bcd13596da48b25f Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 9 Mar 2021 16:32:55 -0600 Subject: finish hw --- csci4131/hw4/strap012/strap012.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'csci4131/hw4') diff --git a/csci4131/hw4/strap012/strap012.py b/csci4131/hw4/strap012/strap012.py index 17571f1..af0f800 100644 --- a/csci4131/hw4/strap012/strap012.py +++ b/csci4131/hw4/strap012/strap012.py @@ -25,12 +25,9 @@ def check_perms(resource): def POST(form): form = unquote(form) form = form.replace("+", " ") - form = form.split("&") - print(form) contents = "" for x in form: x = x.split("=") - print(x) contents = contents + "\n" + x[0] + "\n" + x[1] + "\n\n" table = "" + contents + "
" ret = "\n\n\n\n\nTest\n\n\n

\nFollowing Form Data Submitted Successfully:


\n{}\n\n".format(table) @@ -38,14 +35,13 @@ def POST(form): def getContents(type, file, contents): if type =="POST": - if file != "redirect": - return b"".join( + return b"".join( [OK.encode(), POST(contents).encode(), "{}{}".format(CRLF, CRLF).encode()]) - else: - contents = contents.split("=")[-1] - return "HTTP/1.1 307 TEMPORARY REDIRECT{}Connection: close{}Location:{}{}{}".format(CRLF, CRLF, "https://youtube.com/results?search_query=" + contents, CRLF, CRLF).encode() returnValue = "".encode() try: + if file.split("?")[0] == "redirect": + contents = file.split("?")[1].split("=")[-1] + return "HTTP/1.1 307 TEMPORARY REDIRECT{}Connection: close{}Location:{}{}{}".format(CRLF, CRLF, "https://youtube.com/results?search_query=" + contents, CRLF, CRLF).encode() if not check_perms(file): raise PermissionError content = open(file, 'rb') -- cgit v1.2.3