Skip to content
Merged
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
18 changes: 9 additions & 9 deletions fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def form2dict(form: FormData) -> dict:
async def parse_form(req: Request) -> FormData:
"Starlette errors on empty multipart forms, so this checks for that situation"
ctype = req.headers.get("Content-Type", "")
if ctype=='application/json': return await req.json()
if not ctype.startswith("multipart/form-data"): return await req.form()
try: boundary = ctype.split("boundary=")[1].strip()
except IndexError: raise HTTPException(400, "Invalid form-data: no boundary")
min_len = len(boundary) + 6
clen = int(req.headers.get("Content-Length", "0"))
if clen <= min_len: return FormData()
return await req.form()
if ctype.startswith("multipart/form-data"):
try: boundary = ctype.split("boundary=")[1].strip()
except IndexError: raise HTTPException(400, "Invalid form-data: no boundary")
if int(req.headers.get("Content-Length", "0")) <= len(boundary) + 6: return FormData()
return await req.form()
await req.body() # Cache body for non-multipart request types
return await req.json() if ctype == 'application/json' else await req.form()


# %% ../nbs/api/00_core.ipynb #089fe388
async def _from_body(conn, p, data):
Expand Down Expand Up @@ -368,7 +368,7 @@ def _to_xml(req, resp, indent):
"Convert response to XML string with target URL resolution"
resp = _apply_ft(resp)
_find_targets(req, resp)
return to_xml(resp, indent)
return to_xml(resp, indent=indent)

# %% ../nbs/api/00_core.ipynb #f1e3ed2d
_iter_typs = (tuple,list,map,filter,range,types.GeneratorType)
Expand Down
Loading