|
131 | 131 | {
|
132 | 132 | "data": {
|
133 | 133 | "text/plain": [
|
134 |
| - "datetime.datetime(2025, 5, 8, 14, 0)" |
| 134 | + "datetime.datetime(2025, 5, 12, 14, 0)" |
135 | 135 | ]
|
136 | 136 | },
|
137 |
| - "execution_count": null, |
| 137 | + "execution_count": 6, |
138 | 138 | "metadata": {},
|
139 | 139 | "output_type": "execute_result"
|
140 | 140 | }
|
|
155 | 155 | "True"
|
156 | 156 | ]
|
157 | 157 | },
|
158 |
| - "execution_count": null, |
| 158 | + "execution_count": 7, |
159 | 159 | "metadata": {},
|
160 | 160 | "output_type": "execute_result"
|
161 | 161 | }
|
|
190 | 190 | "'Snake-Case'"
|
191 | 191 | ]
|
192 | 192 | },
|
193 |
| - "execution_count": null, |
| 193 | + "execution_count": 9, |
194 | 194 | "metadata": {},
|
195 | 195 | "output_type": "execute_result"
|
196 | 196 | }
|
|
262 | 262 | "HtmxHeaders(boosted=None, current_url=None, history_restore_request=None, prompt=None, request='1', target=None, trigger_name=None, trigger=None)"
|
263 | 263 | ]
|
264 | 264 | },
|
265 |
| - "execution_count": null, |
| 265 | + "execution_count": 12, |
266 | 266 | "metadata": {},
|
267 | 267 | "output_type": "execute_result"
|
268 | 268 | }
|
|
407 | 407 | "'HX-Trigger-After-Settle'"
|
408 | 408 | ]
|
409 | 409 | },
|
410 |
| - "execution_count": null, |
| 410 | + "execution_count": 21, |
411 | 411 | "metadata": {},
|
412 | 412 | "output_type": "execute_result"
|
413 | 413 | }
|
|
443 | 443 | "HttpHeader(k='HX-Trigger-After-Settle', v='hi')"
|
444 | 444 | ]
|
445 | 445 | },
|
446 |
| - "execution_count": null, |
| 446 | + "execution_count": 23, |
447 | 447 | "metadata": {},
|
448 | 448 | "output_type": "execute_result"
|
449 | 449 | }
|
|
614 | 614 | "\"['1', '2']\""
|
615 | 615 | ]
|
616 | 616 | },
|
617 |
| - "execution_count": null, |
| 617 | + "execution_count": 33, |
618 | 618 | "metadata": {},
|
619 | 619 | "output_type": "execute_result"
|
620 | 620 | }
|
|
686 | 686 | "name": "stdout",
|
687 | 687 | "output_type": "stream",
|
688 | 688 | "text": [
|
689 |
| - "[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '1', HttpHeader(k='value1', v='value3')]\n" |
| 689 | + "[<starlette.requests.Request object at 0x110409d30>, <starlette.applications.Starlette object at 0x11040aae0>, '1', HttpHeader(k='value1', v='value3')]\n" |
690 | 690 | ]
|
691 | 691 | }
|
692 | 692 | ],
|
|
712 | 712 | "name": "stdout",
|
713 | 713 | "output_type": "stream",
|
714 | 714 | "text": [
|
715 |
| - "[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '1', HttpHeader(k='value1', v='value3')]\n" |
| 715 | + "[<starlette.requests.Request object at 0x110430920>, <starlette.applications.Starlette object at 0x110409eb0>, '1', HttpHeader(k='value1', v='value3')]\n" |
716 | 716 | ]
|
717 | 717 | }
|
718 | 718 | ],
|
|
754 | 754 | "name": "stdout",
|
755 | 755 | "output_type": "stream",
|
756 | 756 | "text": [
|
757 |
| - "[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '']\n" |
| 757 | + "[<starlette.requests.Request object at 0x1104314f0>, <starlette.applications.Starlette object at 0x11040ad20>, '']\n" |
758 | 758 | ]
|
759 | 759 | }
|
760 | 760 | ],
|
|
1240 | 1240 | "#| export\n",
|
1241 | 1241 | "class Redirect:\n",
|
1242 | 1242 | " \"Use HTMX or Starlette RedirectResponse as required to redirect to `loc`\"\n",
|
1243 |
| - " def __init__(self, loc): self.loc = loc\n", |
| 1243 | + " def __init__(self, loc, background: BackgroundTask | None = None):\n", |
| 1244 | + " self.loc,self.background = loc,background\n", |
1244 | 1245 | " def __response__(self, req):\n",
|
| 1246 | + " cts,httphdrs,tasks = _xt_cts(req, [])\n", |
| 1247 | + " if not tasks.tasks: tasks = self.background \n", |
1245 | 1248 | " if 'hx-request' in req.headers: return HtmxResponseHeaders(redirect=self.loc)\n",
|
1246 |
| - " return RedirectResponse(self.loc, status_code=303)" |
| 1249 | + " return RedirectResponse(self.loc, status_code=303, background=tasks)" |
1247 | 1250 | ]
|
1248 | 1251 | },
|
1249 | 1252 | {
|
|
1299 | 1302 | "name": "stdout",
|
1300 | 1303 | "output_type": "stream",
|
1301 | 1304 | "text": [
|
1302 |
| - "head-support preload class-tools loading-states multi-swap path-deps remove-me ws chunked-transfer\n" |
| 1305 | + "morph head-support preload class-tools loading-states multi-swap path-deps remove-me ws chunked-transfer\n" |
1303 | 1306 | ]
|
1304 | 1307 | }
|
1305 | 1308 | ],
|
|
1349 | 1352 | {
|
1350 | 1353 | "data": {
|
1351 | 1354 | "text/plain": [
|
1352 |
| - "'9438c74e-c727-4bdc-940a-350fafb71934'" |
| 1355 | + "'a2597a39-e99d-4460-90b9-2ca21e87bc8f'" |
1353 | 1356 | ]
|
1354 | 1357 | },
|
1355 |
| - "execution_count": null, |
| 1358 | + "execution_count": 68, |
1356 | 1359 | "metadata": {},
|
1357 | 1360 | "output_type": "execute_result"
|
1358 | 1361 | }
|
|
1676 | 1679 | "'f_g'"
|
1677 | 1680 | ]
|
1678 | 1681 | },
|
1679 |
| - "execution_count": null, |
| 1682 | + "execution_count": 85, |
1680 | 1683 | "metadata": {},
|
1681 | 1684 | "output_type": "execute_result"
|
1682 | 1685 | }
|
|
1738 | 1741 | "'/foo?a=bar&b=1&b=2'"
|
1739 | 1742 | ]
|
1740 | 1743 | },
|
1741 |
| - "execution_count": null, |
| 1744 | + "execution_count": 88, |
1742 | 1745 | "metadata": {},
|
1743 | 1746 | "output_type": "execute_result"
|
1744 | 1747 | }
|
|
1763 | 1766 | "'/foo/bar?b=1&b=2'"
|
1764 | 1767 | ]
|
1765 | 1768 | },
|
1766 |
| - "execution_count": null, |
| 1769 | + "execution_count": 89, |
1767 | 1770 | "metadata": {},
|
1768 | 1771 | "output_type": "execute_result"
|
1769 | 1772 | }
|
|
1838 | 1841 | "'test'"
|
1839 | 1842 | ]
|
1840 | 1843 | },
|
1841 |
| - "execution_count": null, |
| 1844 | + "execution_count": 92, |
1842 | 1845 | "metadata": {},
|
1843 | 1846 | "output_type": "execute_result"
|
1844 | 1847 | }
|
|
1905 | 1908 | "'/foo?param=value'"
|
1906 | 1909 | ]
|
1907 | 1910 | },
|
1908 |
| - "execution_count": null, |
| 1911 | + "execution_count": 95, |
1909 | 1912 | "metadata": {},
|
1910 | 1913 | "output_type": "execute_result"
|
1911 | 1914 | }
|
|
1951 | 1954 | "'Hi there'"
|
1952 | 1955 | ]
|
1953 | 1956 | },
|
1954 |
| - "execution_count": null, |
| 1957 | + "execution_count": 97, |
1955 | 1958 | "metadata": {},
|
1956 | 1959 | "output_type": "execute_result"
|
1957 | 1960 | }
|
|
1976 | 1979 | "'Postal'"
|
1977 | 1980 | ]
|
1978 | 1981 | },
|
1979 |
| - "execution_count": null, |
| 1982 | + "execution_count": 98, |
1980 | 1983 | "metadata": {},
|
1981 | 1984 | "output_type": "execute_result"
|
1982 | 1985 | }
|
|
2000 | 2003 | "'testserver'"
|
2001 | 2004 | ]
|
2002 | 2005 | },
|
2003 |
| - "execution_count": null, |
| 2006 | + "execution_count": 99, |
2004 | 2007 | "metadata": {},
|
2005 | 2008 | "output_type": "execute_result"
|
2006 | 2009 | }
|
|
2055 | 2058 | "'a yoyo'"
|
2056 | 2059 | ]
|
2057 | 2060 | },
|
2058 |
| - "execution_count": null, |
| 2061 | + "execution_count": 101, |
2059 | 2062 | "metadata": {},
|
2060 | 2063 | "output_type": "execute_result"
|
2061 | 2064 | }
|
|
2153 | 2156 | "'Good day to you, Alexis!'"
|
2154 | 2157 | ]
|
2155 | 2158 | },
|
2156 |
| - "execution_count": null, |
| 2159 | + "execution_count": 105, |
2157 | 2160 | "metadata": {},
|
2158 | 2161 | "output_type": "execute_result"
|
2159 | 2162 | }
|
|
2200 | 2203 | "'http://testserver/user/Alexis; http://testserver/hostie'"
|
2201 | 2204 | ]
|
2202 | 2205 | },
|
2203 |
| - "execution_count": null, |
| 2206 | + "execution_count": 107, |
2204 | 2207 | "metadata": {},
|
2205 | 2208 | "output_type": "execute_result"
|
2206 | 2209 | }
|
|
2366 | 2369 | "'got sub/a.b'"
|
2367 | 2370 | ]
|
2368 | 2371 | },
|
2369 |
| - "execution_count": null, |
| 2372 | + "execution_count": 116, |
2370 | 2373 | "metadata": {},
|
2371 | 2374 | "output_type": "execute_result"
|
2372 | 2375 | }
|
|
2696 | 2699 | "name": "stdout",
|
2697 | 2700 | "output_type": "stream",
|
2698 | 2701 | "text": [
|
2699 |
| - "Set to 2025-05-08 10:13:46.558923\n" |
| 2702 | + "Set to 2025-05-12 15:48:45.492699\n" |
2700 | 2703 | ]
|
2701 | 2704 | },
|
2702 | 2705 | {
|
2703 | 2706 | "data": {
|
2704 | 2707 | "text/plain": [
|
2705 |
| - "'Session time: 2025-05-08 10:13:46.558923'" |
| 2708 | + "'Session time: 2025-05-12 15:48:45.492699'" |
2706 | 2709 | ]
|
2707 | 2710 | },
|
2708 |
| - "execution_count": null, |
| 2711 | + "execution_count": 135, |
2709 | 2712 | "metadata": {},
|
2710 | 2713 | "output_type": "execute_result"
|
2711 | 2714 | }
|
|
3223 | 3226 | {
|
3224 | 3227 | "data": {
|
3225 | 3228 | "text/plain": [
|
3226 |
| - "'Cookie was set at time 10:13:47.275192'" |
| 3229 | + "'Cookie was set at time 15:48:45.745938'" |
3227 | 3230 | ]
|
3228 | 3231 | },
|
3229 |
| - "execution_count": null, |
| 3232 | + "execution_count": 163, |
3230 | 3233 | "metadata": {},
|
3231 | 3234 | "output_type": "execute_result"
|
3232 | 3235 | }
|
|
3469 | 3472 | "test_eq(r.status_code, 200)"
|
3470 | 3473 | ]
|
3471 | 3474 | },
|
| 3475 | + { |
| 3476 | + "cell_type": "markdown", |
| 3477 | + "id": "45274d5d", |
| 3478 | + "metadata": {}, |
| 3479 | + "source": [ |
| 3480 | + "Test against redirect:" |
| 3481 | + ] |
| 3482 | + }, |
| 3483 | + { |
| 3484 | + "cell_type": "code", |
| 3485 | + "execution_count": null, |
| 3486 | + "id": "f08266cc", |
| 3487 | + "metadata": {}, |
| 3488 | + "outputs": [ |
| 3489 | + { |
| 3490 | + "name": "stdout", |
| 3491 | + "output_type": "stream", |
| 3492 | + "text": [ |
| 3493 | + "Starting slow task\n", |
| 3494 | + "Finished slow task\n" |
| 3495 | + ] |
| 3496 | + } |
| 3497 | + ], |
| 3498 | + "source": [ |
| 3499 | + "@rt('/background-redirect')\n", |
| 3500 | + "def get():\n", |
| 3501 | + " return Redirect('/', background=BackgroundTask(my_slow_task))\n", |
| 3502 | + "\n", |
| 3503 | + "r = cli.get('/background-redirect', follow_redirects=False)\n", |
| 3504 | + "\n", |
| 3505 | + "test_eq(r.status_code, 303)" |
| 3506 | + ] |
| 3507 | + }, |
3472 | 3508 | {
|
3473 | 3509 | "cell_type": "code",
|
3474 | 3510 | "execution_count": null,
|
|
0 commit comments