From 2dd49942595b451780f5b86252bbc17b8c7590ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?= <cuu508@gmail.com>
Date: Fri, 20 Dec 2024 11:38:33 +0200
Subject: [PATCH] Fix fetchstatus.py (again) to handle SITE_ROOT with a path

cc: #1108
---
 CHANGELOG.md          | 8 ++++++++
 docker/fetchstatus.py | 9 ++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83e2dfb4..abbc5e85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,14 @@
 # Changelog
 All notable changes to this project will be documented in this file.
 
+## v3.9 - 2024-12-20
+
+### Improvements
+- Change the default value of ALLOWED_HOSTS from "*" to the domain part of SITE_ROOT
+
+### Bug Fixes
+- Fix fetchstatus.py (again) to handle SITE_ROOT with a path (#1108)
+
 ## v3.8.2 - 2024-12-19
 
 ### Improvements
diff --git a/docker/fetchstatus.py b/docker/fetchstatus.py
index d989e72a..840d4a10 100755
--- a/docker/fetchstatus.py
+++ b/docker/fetchstatus.py
@@ -20,7 +20,8 @@ settings.py uses for reading SITE_ROOT:
 from __future__ import annotations
 
 import os
-from urllib.request import urlopen
+from urllib.parse import urlparse
+from urllib.request import Request, urlopen
 
 # Read SITE_ROOT from environment, same as settings.py would do:
 SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
@@ -30,8 +31,10 @@ if os.path.exists("hc/local_settings.py"):
 
     SITE_ROOT = getattr(local_settings, "SITE_ROOT", SITE_ROOT)
 
-SITE_ROOT = SITE_ROOT.removesuffix("/")
-with urlopen(f"{SITE_ROOT}/api/v3/status/") as response:
+parsed_site_root = urlparse(SITE_ROOT.removesuffix("/"))
+url = f"http://localhost:8000{parsed_site_root.path}/api/v3/status/"
+headers = {"Host": parsed_site_root.netloc}
+with urlopen(Request(url, headers=headers)) as response:
     assert response.status == 200
 
 print("Status OK")