Skip to content

Instantly share code, notes, and snippets.

@synodriver
Created August 16, 2022 09:22
Show Gist options
  • Save synodriver/66abc632f42f75e6b05ef60aa3a484d8 to your computer and use it in GitHub Desktop.
Save synodriver/66abc632f42f75e6b05ef60aa3a484d8 to your computer and use it in GitHub Desktop.
A simple app to test trailer extension
async def app2(scope, receive, send):
if scope["type"] == "http":
# request = Request(scope, receive)
# body = await request.body()
# print(body)
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [
(b"Trailer", b"X-Test"),
(b"Cache-Control", b"no-cache"),
(b"Content-Type", b"text/plain"),
],
"meta": {"reason": "OK"},
}
)
await send({"type": "http.response.body", "body": b"test body", "more_body": True})
await send({"type": "http.response.trailers", "headers": [(b"X-Test", b"test")]})
if __name__ == "__main__":
# actually this is nonecorn
from hypercorn.asyncio import serve
from hypercorn.config import Config
try:
import uvloop
uvloop.install()
except ImportError:
pass
kw = {"bind": ["127.0.0.1:9001"], "accesslog": "-", "loglevel": "DEBUG"}
config = Config.from_mapping(kw)
# config.keyfile = ".\key.pem"
# config.certfile = ".\cert.pem"
asyncio.run(serve(app2, config))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment