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

Documentation for Response.asgi_send(send) method #1266

Closed
simonw opened this issue Mar 19, 2021 · 1 comment
Closed

Documentation for Response.asgi_send(send) method #1266

simonw opened this issue Mar 19, 2021 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Mar 19, 2021

I found myself wanting to use this method for simonw/datasette-auth-passwords#15 - but it's not documented. It should be documented.

async def asgi_send(self, send):
headers = {}
headers.update(self.headers)
headers["content-type"] = self.content_type
raw_headers = [
[key.encode("utf-8"), value.encode("utf-8")]
for key, value in headers.items()
]
for set_cookie in self._set_cookie_headers:
raw_headers.append([b"set-cookie", set_cookie.encode("utf-8")])
await send(
{
"type": "http.response.start",
"status": self.status,
"headers": raw_headers,
}
)
body = self.body
if not isinstance(body, bytes):
body = body.encode("utf-8")
await send({"type": "http.response.body", "body": body})

@simonw
Copy link
Owner Author

simonw commented Mar 20, 2021

simonw added a commit that referenced this issue Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant