Skip to content

ASGI HTTP support#3571

Draft
takluyver wants to merge 10 commits intotornadoweb:masterfrom
takluyver:asgi
Draft

ASGI HTTP support#3571
takluyver wants to merge 10 commits intotornadoweb:masterfrom
takluyver:asgi

Conversation

@takluyver
Copy link
Contributor

Basic support for wrapping a tornado web Application class and serving HTTP requests through an ASGI server.

This obviously needs tests, but I've been able to start a server and serve a basic request locally:

# asgi_eg.py
from tornado.web import Application, RequestHandler
from tornado.asgi import ASGIAdapter

class MainHandler(RequestHandler):
    def get(self):
        self.write("Hello, world")

asgi_app = ASGIAdapter(
    Application([
        (r"/", MainHandler),
    ])
)
daphne asgi_eg:asgi_app

@takluyver
Copy link
Contributor Author

@bdarnell when you've got a moment, it would be great if you could have a quick look to see if I'm going in the direction you'd expect, both in the implementation and in the tests. It's relatively easy to make bigger changes while the added code is quite small.

There are 2 main new classes:

  • ASGIAdapter wraps a tornado Application and provides the ASGI entry point
  • ASGIHTTPConnection provides the API for a RequestHandler to send its response

Things I'm aware of that the tests should cover:

  • Testing with at least 1 real ASGI server, i.e. listening on a socket
  • HTTP/2
  • Behaviour when data is streamed, both for the request and the response
  • Either side closing the connection early
  • Non-ASCII characters in various places

(I'm sure that's not exhaustive, just writing down what I can think of now)

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.

1 participant