@@ -29,28 +29,49 @@ async def get(self, url) -> None:
2929 try :
3030 client = httpclient .AsyncHTTPClient ()
3131
32- # Check the user-provided url
32+ # First check for the individual-plots endpoint at user-provided url.
33+ # We don't check for the root URL because that can trigger a lot of
34+ # object creation in the bokeh document.
3335 url = _normalize_dashboard_link (parse .unquote (url ), self .request )
36+ effective_url = None
3437 individual_plots_url = url_path_join (
3538 url ,
3639 "individual-plots.json" ,
3740 )
38- self .log .debug (f"Checking for individual plots at { individual_plots_url } " )
39- response = await client .fetch (individual_plots_url )
41+ try :
42+ self .log .debug (
43+ f"Checking for individual plots at { individual_plots_url } "
44+ )
45+ individual_plots_response = await client .fetch (individual_plots_url )
46+ self .log .debug (f"{ individual_plots_response .code } " )
47+ except httpclient .HTTPError as err :
48+ # If we didn't get individual plots, we may have to follow a redirect first.
49+ self .log .debug (f"Checking for redirect at { url } " )
50+ response = await client .fetch (url )
51+ effective_url = (
52+ _normalize_dashboard_link (response .effective_url , self .request )
53+ if response .effective_url != url
54+ else None
55+ )
56+ # If there was no redirect, raise.
57+ if not effective_url :
58+ raise err
59+
60+ individual_plots_url = url_path_join (
61+ effective_url ,
62+ "individual-plots.json" ,
63+ )
64+ self .log .debug (f"Found redirect at { effective_url } " )
65+ self .log .debug (
66+ f"Checking for individual plots at { individual_plots_url } "
67+ )
68+ individual_plots_response = await client .fetch (individual_plots_url )
4069
4170 # If we didn't get individual plots, it may not be a dask dashboard
42- if response .code != 200 :
71+ if individual_plots_response .code != 200 :
4372 raise ValueError ("Does not seem to host a dask dashboard" )
4473
45- # If the effective URL is different, strip off the individual-plots
46- # endpoint and include that as well.
47- effective_url = (
48- response .effective_url [: - len ("individual-plots.json" )]
49- if response .effective_url != individual_plots_url
50- else None
51- )
52-
53- individual_plots = json .loads (response .body )
74+ individual_plots = json .loads (individual_plots_response .body )
5475
5576 self .set_status (200 )
5677 self .finish (
0 commit comments