|
84 | 84 | "\n", |
85 | 85 | "from fastcore.test import *\n", |
86 | 86 | "from starlette.testclient import TestClient\n", |
87 | | - "from starlette.requests import Headers\n", |
88 | 87 | "from starlette.datastructures import UploadFile" |
89 | 88 | ] |
90 | 89 | }, |
|
131 | 130 | { |
132 | 131 | "data": { |
133 | 132 | "text/plain": [ |
134 | | - "datetime.datetime(2026, 3, 9, 14, 0)" |
| 133 | + "datetime.datetime(2026, 3, 14, 14, 0)" |
135 | 134 | ] |
136 | 135 | }, |
137 | 136 | "execution_count": null, |
|
1785 | 1784 | " if self.host:\n", |
1786 | 1785 | " host = Headers(scope=scope).get(\"host\", \"\").split(\":\")[0]\n", |
1787 | 1786 | " if not self.host_regex.match(host): return Match.NONE, {}\n", |
1788 | | - " return super().matches(scope)" |
| 1787 | + " return super().matches(scope)\n", |
| 1788 | + "\n", |
| 1789 | + " def __repr__(self) -> str:\n", |
| 1790 | + " methods = sorted(self.methods or [])\n", |
| 1791 | + " return f\"{self.__class__.__name__}(path={self.path!r}, name={self.name!r}, methods={methods!r}, host={self.host!r})\"" |
1789 | 1792 | ] |
1790 | 1793 | }, |
1791 | 1794 | { |
|
2243 | 2246 | "name": "stdout", |
2244 | 2247 | "output_type": "stream", |
2245 | 2248 | "text": [ |
2246 | | - "[HostRoute(path='/foo', name='foo', methods=['GET', 'HEAD'])]\n" |
| 2249 | + "[HostRoute(path='/foo', name='foo', methods=['GET', 'HEAD'], host=None)]\n" |
2247 | 2250 | ] |
2248 | 2251 | }, |
2249 | 2252 | { |
|
2270 | 2273 | "foo.to(param='value')" |
2271 | 2274 | ] |
2272 | 2275 | }, |
| 2276 | + { |
| 2277 | + "cell_type": "code", |
| 2278 | + "execution_count": null, |
| 2279 | + "id": "8836b62c", |
| 2280 | + "metadata": {}, |
| 2281 | + "outputs": [ |
| 2282 | + { |
| 2283 | + "name": "stdout", |
| 2284 | + "output_type": "stream", |
| 2285 | + "text": [ |
| 2286 | + "[HostRoute(path='/foo', name='foo', methods=['GET', 'HEAD', 'POST'], host='test.foo'), HostRoute(path='/foo', name='foo', methods=['GET', 'HEAD'], host=None)]\n" |
| 2287 | + ] |
| 2288 | + } |
| 2289 | + ], |
| 2290 | + "source": [ |
| 2291 | + "@rt(host='test.foo')\n", |
| 2292 | + "def foo(): return Div(\"Goodbye World\")\n", |
| 2293 | + "\n", |
| 2294 | + "print(app.routes)\n", |
| 2295 | + "\n", |
| 2296 | + "assert \"Goodbye World\" in cli.get('/foo', headers={'host': 'test.foo'}).text\n", |
| 2297 | + "assert \"Hello World\" in cli.get('/foo').text" |
| 2298 | + ] |
| 2299 | + }, |
| 2300 | + { |
| 2301 | + "cell_type": "code", |
| 2302 | + "execution_count": null, |
| 2303 | + "id": "377012de", |
| 2304 | + "metadata": {}, |
| 2305 | + "outputs": [ |
| 2306 | + { |
| 2307 | + "data": { |
| 2308 | + "text/plain": [ |
| 2309 | + "'/foo?param=value'" |
| 2310 | + ] |
| 2311 | + }, |
| 2312 | + "execution_count": null, |
| 2313 | + "metadata": {}, |
| 2314 | + "output_type": "execute_result" |
| 2315 | + } |
| 2316 | + ], |
| 2317 | + "source": [ |
| 2318 | + "response = cli.get('/foo')\n", |
| 2319 | + "assert '<title>My Custom Title</title>' in response.text\n", |
| 2320 | + "\n", |
| 2321 | + "foo.to(param='value')" |
| 2322 | + ] |
| 2323 | + }, |
2273 | 2324 | { |
2274 | 2325 | "cell_type": "code", |
2275 | 2326 | "execution_count": null, |
|
2371 | 2422 | "text": [ |
2372 | 2423 | "Message text was: Hi! with session bar, from client: Address(host='testclient', port=50000)\n" |
2373 | 2424 | ] |
2374 | | - }, |
2375 | | - { |
2376 | | - "name": "stderr", |
2377 | | - "output_type": "stream", |
2378 | | - "text": [ |
2379 | | - "/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_76694/1456865336.py:30: UserWarning: `self has no type annotation and is not a recognised special name, so is ignored.\n", |
2380 | | - " if arg!='resp': warn(f\"`{arg} has no type annotation and is not a recognised special name, so is ignored.\")\n" |
2381 | | - ] |
2382 | 2425 | } |
2383 | 2426 | ], |
2384 | 2427 | "source": [ |
|
3087 | 3130 | "name": "stdout", |
3088 | 3131 | "output_type": "stream", |
3089 | 3132 | "text": [ |
3090 | | - "Set to 2026-03-09 16:07:07.828671\n" |
| 3133 | + "Set to 2026-03-14 06:34:21.131035\n" |
3091 | 3134 | ] |
3092 | 3135 | }, |
3093 | 3136 | { |
3094 | 3137 | "data": { |
3095 | 3138 | "text/plain": [ |
3096 | | - "'Session time: 2026-03-09 16:07:07.828671'" |
| 3139 | + "'Session time: 2026-03-14 06:34:21.131035'" |
3097 | 3140 | ] |
3098 | 3141 | }, |
3099 | 3142 | "execution_count": null, |
|
3710 | 3753 | { |
3711 | 3754 | "data": { |
3712 | 3755 | "text/plain": [ |
3713 | | - "'Cookie was set at time 16:07:08.723344'" |
| 3756 | + "'Cookie was set at time 06:34:21.699929'" |
3714 | 3757 | ] |
3715 | 3758 | }, |
3716 | 3759 | "execution_count": null, |
|
0 commit comments