Skip to content

Commit f638295

Browse files
authored
Merge pull request #258 from ntabris/preserve-url-query
Append any URL query args to dashboard URL paths
2 parents 4c23d29 + 55d0bb1 commit f638295

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

dask_labextension/dashboardhandler.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ async def get(self, url) -> None:
2929
try:
3030
client = httpclient.AsyncHTTPClient()
3131

32+
# Extract query (if any) from URL, this will then be appended after path.
33+
# This allows using (eg) "?token=[...]" in URL for authentication.
34+
if "?" in url:
35+
pos = url.find("?")
36+
url, query = url[:pos], url[pos:]
37+
else:
38+
query = ""
39+
3240
# First check for the individual-plots endpoint at user-provided url.
3341
# We don't check for the root URL because that can trigger a lot of
3442
# object creation in the bokeh document.
3543
url = _normalize_dashboard_link(parse.unquote(url), self.request)
3644
effective_url = None
3745
individual_plots_url = url_path_join(
3846
url,
39-
"individual-plots.json",
47+
f"individual-plots.json{query}",
4048
)
4149
try:
4250
self.log.debug(
@@ -73,6 +81,14 @@ async def get(self, url) -> None:
7381

7482
individual_plots = json.loads(individual_plots_response.body)
7583

84+
# If there was query in original URL, append to URLs returned
85+
if query:
86+
for name, plot_url in individual_plots.items():
87+
individual_plots[name] = f"{plot_url}{query}"
88+
url = f"{url}{query}"
89+
if effective_url:
90+
effective_url = f"{effective_url}{query}"
91+
7692
self.set_status(200)
7793
self.finish(
7894
json.dumps(

0 commit comments

Comments
 (0)