pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is Hypercorn server serving up response using HTTP/2

sandeep12rana opened this issue · comments

Here is the implementation stub

from hypercorn.config import Config as HyperCornConfig
from hyercorn.asyncio import serve
import asyncio

class FastApiServer:
def init(self) -> None:
self._hypercorn_config = HyperCornConfig()
self._fastapi_instance = get_fast_api_instance()

async def run_server(self):
    self._hypercorn_config.bind = ["127.0.0.1:8091"]
    await serve(self._fastapi_instance , self._hypercorn_config)

async def main():
fastapiserver = FastApiServer()
await fastapiserver.run_server()

if name == "main":
asyncio.run(main())

When running in local , on Chrome, the API call gives a response. but on Protocol (in developer's tool) it shows http/1.1 and not http/2.

what am i missing?

AFAIK, chrome will only initiate an H2 connection over SSL/TLS. So you could create a self-signed cert and have hypercorn present it either via the config class or via the command line. Chrome will obviously error on invalid cert but you can then ignore the error. It will then initiate an HTTP/2 connection.

Hope this helps.