From f55ab33375345c754368ab17c8c63d192c0ade54 Mon Sep 17 00:00:00 2001 From: Kristijan Burnik Date: Fri, 17 Jul 2015 15:04:10 +0200 Subject: [PATCH] Implement 405 for unhandled non-GET requests. --- wptserve/server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wptserve/server.py b/wptserve/server.py index 78b982c..a41f42a 100644 --- a/wptserve/server.py +++ b/wptserve/server.py @@ -242,7 +242,13 @@ def handle_one_request(self): time.sleep(latency / 1000.) if handler is None: - response.set_error(404) + if request.method in ["GET"]: + # Assume no handler means path to a non-existing resource. + response.set_error(404, "Not found") + else: + # Using a non-GET method without a dedicated handler is + # considered not allowed. E.g. if requesting files via POST. + response.set_error(405, "Method not allowed") else: try: handler(request, response)