From a4025bdd77db1fe17ed8388e33ef003d6c7d8999 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Sun, 7 Mar 2021 16:07:18 -0600 Subject: Fix the screwyness --- csci4131/hw4/strap012/strap012.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'csci4131/hw4/strap012') diff --git a/csci4131/hw4/strap012/strap012.py b/csci4131/hw4/strap012/strap012.py index ff55926..d6d6385 100644 --- a/csci4131/hw4/strap012/strap012.py +++ b/csci4131/hw4/strap012/strap012.py @@ -9,21 +9,23 @@ from argparse import ArgumentParser BUFSIZE = 4096 CRLF = '\r\n' METHOD_NOT_ALLOWED = 'HTTP/1.1 405 METHOD NOT ALLOWED{}Allow: GET, HEAD, POST {}Connection: close{}{}'.format(CRLF, CRLF, CRLF, CRLF) -OK = 'HTTP/1.1 200 OK{}{}{}'.format(CRLF, CRLF, CRLF) # head request only +OK = 'HTTP/1.1 200 OK{}{}'.format(CRLF, CRLF, CRLF) # head request only def getContents(type, file): returnValue = "".encode() try: content = open(file, 'rb') except FileNotFoundError: - getContents(type, "404.html") + returnValue = getContents(type, "404.html") except PermissionError: - getContents(type, "403.html") + returnValue = getContents(type, "403.html") else: if type == "HEAD" or "GET": returnValue = OK.encode() if type == "GET": - returnValue =b"".join([returnValue, content.read(), "{}{}".format(CRLF, CRLF).encode()]) + returnValue = b"".join([returnValue, content.read(), "{}{}".format(CRLF, CRLF).encode()]) + else: + returnValue = b"".join([returnValue, "{}{}".format(CRLF, CRLF).encode()]) elif type == "POST": print("B") else: -- cgit v1.2.3