Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
26 changes: 5 additions & 21 deletions web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down Expand Up @@ -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)):
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,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
Expand Down
Loading