Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bring code borrowed from http.server in sync with upstream #4379

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,6 +77,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. """
Expand Down Expand Up @@ -237,11 +237,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)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already deleted this translate_path fuction so I think you would have modified this if state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the re-implementation of the translate_path function, this calls SimpleHTTPRequestHandler.translate_path() - translating the path with the root set to www_root.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK, I didn't noticed that.

self.path = 'index.html'

Expand Down Expand Up @@ -464,26 +467,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:
"""
Expand Down
Loading