From 77c816f75eccd477958ae150f6bab4e1fa947f3e Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Tue, 9 Mar 2021 09:17:25 -0600 Subject: Fix some small errors, begin to implement POST --- csci4131/hw4/strap012/strap012.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'csci4131') diff --git a/csci4131/hw4/strap012/strap012.py b/csci4131/hw4/strap012/strap012.py index df63e4f..43b7efb 100644 --- a/csci4131/hw4/strap012/strap012.py +++ b/csci4131/hw4/strap012/strap012.py @@ -20,6 +20,11 @@ def check_perms(resource): stmode = os.stat(resource).st_mode return(getattr(stat, 'S_IROTH') & stmode) > 0 +def POST(form): + contents = form.decode(utf-8) + print(contents) + return + def getContents(type, file): returnValue = "".encode() try: @@ -45,7 +50,9 @@ def getContents(type, file): returnValue = b"".join( [returnValue, content.read(), "{}{}".format(CRLF, CRLF).encode()]) elif type == "POST": - print("B") + POST(content.read()) + #returnValue = b"".join( + # [returnValue, POST(content.read(), "{}{}".format(CRLF, CRLF).encode())]) else: returnValue= METHOD_NOT_ALLOWED.encode() content.close() @@ -55,12 +62,12 @@ def client_recv(client_sock, client_addr): print('talking to {}'.format(client_addr)) data = client_sock.recv(BUFSIZE) data = data.decode('utf-8').strip("\r") + print(data) data = data.split("\n") request = data[0].split(" ") - if len(data) != 0: + if len(request) > 1: want = getContents(request[0], request[1][1:]) client_sock.send(want) - print(want) client_sock.shutdown(1) client_sock.close() -- cgit v1.2.3