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

Is Hypercorn server serving up response using HTTP/2 #220

Closed
sandeep12rana opened this issue May 5, 2024 · 1 comment
Closed

Is Hypercorn server serving up response using HTTP/2 #220

sandeep12rana opened this issue May 5, 2024 · 1 comment

Comments

@sandeep12rana
Copy link

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?

@nabheet
Copy link

nabheet commented May 13, 2024

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.

@pgjones pgjones closed this as completed May 27, 2024
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

No branches or pull requests

3 participants