From 431eaab7c8308673b7099f1ff9362add55385800 Mon Sep 17 00:00:00 2001 From: Skillet Date: Sun, 13 Aug 2023 18:08:10 -0400 Subject: [PATCH] return 404 incase of bad request link --- simpleFileServer.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/simpleFileServer.py b/simpleFileServer.py index a70afed..6ff51f6 100644 --- a/simpleFileServer.py +++ b/simpleFileServer.py @@ -15,9 +15,6 @@ PORT = 8000 class serveRA(http.server.SimpleHTTPRequestHandler): def do_GET(self): - self.send_response(200) - self.send_header("Content-type", "text") - self.end_headers() query = parse_qs(urlparse(self.path).query) if 'grpName' in query: grpName = query['grpName'][0] @@ -57,8 +54,14 @@ class serveRA(http.server.SimpleHTTPRequestHandler): self.copyfile(file, self.wfile) file.close() except: - print('failed to open file!', file=stderr) + print('failed to serve file!', file=stderr) print(traceback.format_exc(), file=stderr) + + self.send_response(200) + self.send_header("Content-type", "text") + self.end_headers() + else: + self.send_response(404) return