From 5062c119453a9f166e1a14e6c0e076bcddb5554c Mon Sep 17 00:00:00 2001 From: Discookie Date: Mon, 4 Nov 2024 09:41:13 +0000 Subject: [PATCH 1/2] Bring code borrowed from `SimpleHTTPServer` in sync with upstream --- web/server/codechecker_server/server.py | 26 +++++-------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/web/server/codechecker_server/server.py b/web/server/codechecker_server/server.py index 2439dc4787..e9724c3a7a 100644 --- a/web/server/codechecker_server/server.py +++ b/web/server/codechecker_server/server.py @@ -79,6 +79,8 @@ class RequestHandler(SimpleHTTPRequestHandler): def __init__(self, request, client_address, server): self.path = None super().__init__(request, client_address, server) + # GET requests are served from www_root. + self.directory = server.www_root def log_message(self, *args): """ Silencing http server. """ @@ -237,11 +239,14 @@ def do_GET(self): # Check that path contains a product endpoint. if product_endpoint is not None and product_endpoint != '': self.path = self.path.replace(f"{product_endpoint}/", "", 1) + # Remove extra leading slashes, see cpython#93789. + self.path = '/' + self.path.lstrip('/') if self.path == '/': self.path = "index.html" # Check that the given path is a file. + # The base directory is set to www_root. if not os.path.exists(self.translate_path(self.path)): self.path = 'index.html' @@ -464,27 +469,6 @@ def list_directory(self, path): """ Disable directory listing. """ self.send_error(405, "No permission to list directory") - def translate_path(self, path): - """ - Modified version from SimpleHTTPRequestHandler. - Path is set to www_root. - """ - # Abandon query parameters. - path = path.split('?', 1)[0] - path = path.split('#', 1)[0] - path = posixpath.normpath(urllib.parse.unquote(path)) - words = path.split('/') - words = [_f for _f in words if _f] - path = self.server.www_root - for word in words: - _, word = os.path.splitdrive(word) - _, word = os.path.split(word) - if word in (os.curdir, os.pardir): - continue - path = os.path.join(path, word) - return path - - class Product: """ Represents a product, which is a distinct storage of analysis reports in From 208d43bc2c360bfcd85759f7bcfaafec45c80009 Mon Sep 17 00:00:00 2001 From: Discookie Date: Wed, 6 Nov 2024 10:32:53 +0000 Subject: [PATCH 2/2] Remove unused imports --- web/server/codechecker_server/server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/server/codechecker_server/server.py b/web/server/codechecker_server/server.py index e9724c3a7a..99327ac1b5 100644 --- a/web/server/codechecker_server/server.py +++ b/web/server/codechecker_server/server.py @@ -16,14 +16,12 @@ from functools import partial from http.server import HTTPServer, SimpleHTTPRequestHandler import os -import posixpath import shutil import signal import socket import ssl import sys from typing import List, Optional, Tuple -import urllib import multiprocess from sqlalchemy.orm import sessionmaker @@ -469,6 +467,7 @@ def list_directory(self, path): """ Disable directory listing. """ self.send_error(405, "No permission to list directory") + class Product: """ Represents a product, which is a distinct storage of analysis reports in