Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raw_path to scope in ASGITransport #1357

Merged
merged 2 commits into from
Oct 9, 2020
Merged

Add raw_path to scope in ASGITransport #1357

merged 2 commits into from
Oct 9, 2020

Conversation

simonw
Copy link
Contributor

@simonw simonw commented Oct 9, 2020

Closes #1356

@@ -23,6 +23,15 @@ async def echo_path(scope, receive, send):
await send({"type": "http.response.body", "body": output})


async def echo_raw_path(scope, receive, send):
status = 200
output = json.dumps({"raw_path": repr(scope["raw_path"])}).encode("utf-8")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using repr(scope["raw_path"]) here as an easy way to confirm that the value is indeed a Python bytestring - it ends up being returned as "b'/user%40example.org'" in the JSON.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that make sense.

I guess it might look a bit confusing to future readers, so we could either:

  1. Comment it.
  2. Switch it around to {"raw_path": scope["raw_path"].decode("ascii")}

I'd marginally prefer (2), since it's actually perfectly sufficient here, but I'm okay enough with either.

@tomchristie tomchristie merged commit ca5f524 into encode:master Oct 9, 2020
@tomchristie
Copy link
Member

Fab, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASGITransport does not correctly simulate raw_path in the scope
2 participants