Skip to content

Commit

Permalink
Fixed bug were POST didn't re-send form correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 2, 2020
1 parent 82a51e0 commit 84619ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions asgi_csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ async def _parse_form_urlencoded(receive):
more_body = message.get("more_body", False)

async def replay_receive():
for message in messages:
yield message
return messages.pop()

return dict(parse_qsl(body.decode("utf-8"))), replay_receive

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def get_long_description():
license="Apache License, Version 2.0",
version=VERSION,
py_modules=["asgi_csrf"],
extras_require={"test": ["pytest", "pytest-asyncio", "httpx",]},
extras_require={"test": ["pytest", "pytest-asyncio", "httpx", "starlette"]},
)
12 changes: 12 additions & 0 deletions test_asgi_csrf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from asgi_csrf import asgi_csrf
import httpx
import pytest

CSRF_TOKEN = "9izX9q37XP9knNNQ"


async def hello_world(request):
if request.method == "POST":
return JSONResponse(dict(await request.form()))
return JSONResponse({"hello": "world"})


hello_world_app = Starlette(routes=[Route("/", hello_world),])


async def hello_world_app(scope, receive, send):
assert scope["type"] == "http"
await send(
Expand Down

0 comments on commit 84619ed

Please sign in to comment.