Proposal: "http.response.template" extension.
See original GitHub issueIn situations where an application server is happens to be returning template-rendered data, it’s hugely valuable for the template and context information to be sent in the ASGI messaging, alongside the actual rendered content.
Right now we use this in Starlette, so that an ASGI-based test client is able to provide response.template
and response.context
information back to the user.
Formalising this, would allow us to support this kind of usage:
# This client calls directly into an ASGI app, rather than making network requests.
client = httpx.AsyncClient(app=app)
# Make the request.
response = await client.get("http://testserver/")
assert response.status_code == 200
# This information is made available through the "http.response.template" extension.
# Ensure that we're on the homepage, and that no messages are displayed.
assert response.template == "homepage.html"
assert response.context["user_messages"] == []
It’s not totally obvious if an extension such as this should strictly focus on template
/context
info, or if there’s a more general purpose “extra info” extension that ought to be considered here, but I figure it’s worth opening this for discussion.
Informally, here’s ~how the existing Starlette implementation looks…
# If the ASGI `http.response.template` extension is supported,
# then we can send this style of message...
{
"type": "http.response.template",
"template": "homepage.html",
"context": {"user_messages": []}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (15 by maintainers)
It seems too narrow to define this specifically for templates. Perhaps a “execution_info” extension instead, so an app could provide whatever they want back to the test client.
Happily, yup. I’m not in any great rush but I’ll aim to get around to it sometime.