diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-03-07 15:07:57 -0600 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-03-07 15:07:57 -0600 |
commit | 0bab1cb6a5870239356fe8f90aabc4e83f135608 (patch) | |
tree | 51d2e474caf2a0f123f89e313b3466f5827357de | |
parent | start hw4 (diff) | |
download | homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar.gz homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar.bz2 homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar.lz homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar.xz homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.tar.zst homework-0bab1cb6a5870239356fe8f90aabc4e83f135608.zip |
aaaaaaaaaaaaaaaaaaaaaaaaa
Diffstat (limited to '')
-rw-r--r-- | csci4131/hw4/strap012/strap012.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/csci4131/hw4/strap012/strap012.py b/csci4131/hw4/strap012/strap012.py index 7b676c1..862ff7c 100644 --- a/csci4131/hw4/strap012/strap012.py +++ b/csci4131/hw4/strap012/strap012.py @@ -10,23 +10,23 @@ 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 -NOT_FOUND = 'HTTP/1.1 404 NOT FOUND{}Connection: close{}{}'.format(CRLF, CRLF, CRLF) -FORBIDDEN = 'HTTP/1.1 403 FORBIDDEN{}Connection: close{}{}'.format(CRLF, CRLF, CRLF) def getContents(type, file): - fileExist = False returnValue = "" try: - content = open(file) + content = open(file, 'r') except FileNotFoundError: - returnValue = NOT_FOUND + getContents(type, "404.html") except PermissionError: - returnValue = FORBIDDEN + getContents(type, "403.html") else: if type == "HEAD": returnValue = OK elif type == "GET": - returnValue = OK + content.read() + "{}{}".format(CRLF, CRLF) + try: + returnValue = OK + content.read() + "{}{}".format(CRLF, CRLF) + except: + content.close() elif type == "POST": print("B") else: @@ -41,7 +41,6 @@ def client_recv(client_sock, client_addr): data = data.split("\n") request = data[0].split(" ") want = getContents(request[0], request[1][1:]) - print(want) client_sock.send(bytes(want, 'utf-8')) client_sock.shutdown(1) |