Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ async def _find_p(conn, data, hdrs, arg:str, p:Parameter):
if issubclass(anno, Starlette): return conn.scope['app']
if issubclass(anno, HTTPConnection): return conn
if issubclass(anno, State): return conn.scope['app'].state
if anno is dict: return data
if _is_body(anno):
if 'session'.startswith(arg.lower()): return conn.scope.get('session', {})
return await _from_body(conn, p, data)
if anno is dict: return conn.scope.get('session', {}) if 'session'.startswith(arg.lower()) else data
if _is_body(anno): return await _from_body(conn, p, data)
if (msg := _check_anno(arg, anno)): return warn(msg)
# Special param names with no annotations
if anno is empty:
Expand Down
29 changes: 25 additions & 4 deletions nbs/api/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -912,10 +912,8 @@
" if issubclass(anno, Starlette): return conn.scope['app']\n",
" if issubclass(anno, HTTPConnection): return conn\n",
" if issubclass(anno, State): return conn.scope['app'].state\n",
" if anno is dict: return data\n",
" if _is_body(anno):\n",
" if 'session'.startswith(arg.lower()): return conn.scope.get('session', {})\n",
" return await _from_body(conn, p, data)\n",
" if anno is dict: return conn.scope.get('session', {}) if 'session'.startswith(arg.lower()) else data\n",
" if _is_body(anno): return await _from_body(conn, p, data)\n",
" if (msg := _check_anno(arg, anno)): return warn(msg)\n",
" # Special param names with no annotations\n",
" if anno is empty:\n",
Expand Down Expand Up @@ -3514,6 +3512,29 @@
"test_r(cli, '/bodietd/', '{\"a\":1,\"b\":\"foo\"}', 'post', data=d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b57a83f",
"metadata": {},
"outputs": [],
"source": [
"@app.get(\"/set_sess_dict\")\n",
"def _(session:dict):\n",
" session['foo'] = 'bar'\n",
" return 'ok'\n",
"\n",
"@app.get(\"/sess_dict\")\n",
"def _(session:dict): return session.get('foo')\n",
"\n",
"@app.post(\"/s_bodie\")\n",
"def _(s:Bodie): return asdict(s)\n",
"\n",
"cli.get('/set_sess_dict')\n",
"test_r(cli, '/sess_dict?foo=evil', 'bar')\n",
"test_r(cli, '/s_bodie', '{\"a\":1,\"b\":\"foo\"}', 'post', data=d)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down