Skip to content

Commit fade084

Browse files
committed
fixes #2
1 parent 5806b78 commit fade084

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

fasthtml/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def _find_p(req, arg:str, p):
111111
if not res: res = req.query_params.get(arg, None)
112112
if not res: res = req.cookies.get(arg, None)
113113
if not res: res = req.headers.get(snake2hyphens(arg), None)
114-
if not res: res = nested_idx(req.scope, 'session', arg)
114+
if not res: res = nested_idx(req.scope, 'session', arg) or None
115115
if res is empty or res is None:
116116
body = await req.form()
117117
res = body.get(arg, None)

nbs/core_tests.ipynb

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@
421421
"name": "stdout",
422422
"output_type": "stream",
423423
"text": [
424-
"Set to 2024-06-03 12:46:09.633470\n"
424+
"Set to 2024-06-04 09:37:31.288381\n"
425425
]
426426
},
427427
{
428428
"data": {
429429
"text/plain": [
430-
"'Cookie was set at time 12:46:09.633470'"
430+
"'Cookie was set at time 09:37:31.288381'"
431431
]
432432
},
433433
"execution_count": null,
@@ -468,13 +468,13 @@
468468
"name": "stdout",
469469
"output_type": "stream",
470470
"text": [
471-
"Set to 2024-06-03 12:46:10.556040\n"
471+
"Set to 2024-06-04 09:37:31.332236\n"
472472
]
473473
},
474474
{
475475
"data": {
476476
"text/plain": [
477-
"'Session time: 12:46:10.556040'"
477+
"'Session time: 09:37:31.332236'"
478478
]
479479
},
480480
"execution_count": null,
@@ -491,25 +491,49 @@
491491
{
492492
"cell_type": "code",
493493
"execution_count": null,
494-
"id": "021778d1",
494+
"id": "4121c4ab",
495495
"metadata": {},
496-
"outputs": [],
496+
"outputs": [
497+
{
498+
"name": "stdout",
499+
"output_type": "stream",
500+
"text": [
501+
"# Release notes\n",
502+
"\n",
503+
"<!-- do not remove -->\n",
504+
"\n",
505+
"## 0.0.3\n",
506+
"\n",
507+
"- Init release\n",
508+
"\n",
509+
"\n"
510+
]
511+
}
512+
],
497513
"source": [
498-
"auth = user_pwd_auth('testuser', 'spycraft')\n",
499-
"app = FastHTML(middleware=[auth])\n",
500-
"cli = TestClient(app)\n",
501-
"rt = app.route"
514+
"@rt(\"/upload\")\n",
515+
"async def post(uploadfile:str):\n",
516+
" return (await uploadfile.read()).decode()\n",
517+
"\n",
518+
"fn = '../CHANGELOG.md'\n",
519+
"data = {'message': 'Hello, world!'}\n",
520+
"with open(fn, 'rb') as f:\n",
521+
" print(cli.post('/upload', files={'uploadfile': f}, data=data).text)"
502522
]
503523
},
504524
{
505525
"cell_type": "code",
506526
"execution_count": null,
507-
"id": "b46ae684",
527+
"id": "90341316",
508528
"metadata": {},
509529
"outputs": [],
510530
"source": [
511-
"@rt(\"/locked\")\n",
512-
"def get(req): return 'Hello, ' + req.user.display_name\n",
531+
"auth = user_pwd_auth(testuser='spycraft')\n",
532+
"app = FastHTML(middleware=[auth])\n",
533+
"cli = TestClient(app)\n",
534+
"\n",
535+
"@app.route(\"/locked\")\n",
536+
"def get(auth): return 'Hello, ' + auth\n",
513537
"\n",
514538
"test_eq(cli.get('/locked').text, 'not authenticated')\n",
515539
"test_eq(cli.get('/locked', auth=(\"testuser\",\"spycraft\")).text, 'Hello, testuser')"

0 commit comments

Comments
 (0)