Allow forcing HTTPS in URL generation (#92)
* Force HTTPS feature * Add docs
This commit is contained in:
committed by
Christiaan Goossens
parent
f614092af2
commit
c217e46909
@@ -4,12 +4,14 @@ from homeassistant.components import http
|
||||
from .views.loader import AsyncTemplateRenderer
|
||||
|
||||
|
||||
def get_url(path: str) -> str:
|
||||
def get_url(path: str, force_https: bool) -> str:
|
||||
"""Returns the requested path appended to the current request base URL."""
|
||||
if (req := http.current_request.get()) is None:
|
||||
raise RuntimeError("No current request in context")
|
||||
|
||||
base_uri = str(req.url).split("/auth", 2)[0]
|
||||
if force_https:
|
||||
base_uri = base_uri.replace("http://", "https://")
|
||||
return f"{base_uri}{path}"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user