facebook / proxygen

A collection of C++ HTTP libraries including an easy to use HTTP server.
Other
8.16k stars 1.5k forks source link

Running demo HTTP/3 server via browser #418

Closed chanh1964 closed 7 months ago

chanh1964 commented 2 years ago

Hi all. I'm trying to run the demo HTTP/3 server locally via Firefox, but it fails.

I'm using the release v2022.07.04.00. The build and test were successful. I ran the demo hq server using the following command:

_build/proxygen/httpserver/hq \
        --mode=server \
        --h2port=8080 \
        --port=8443 \
        --protocol=h3 \
        --cert=keys/cert.pem \
        --key=keys/key.key \
        --static-root=./

I created a simple index.html file in the static-root dir, and tried to open it in Firefox with the link https://localhost:8443/index.html for HTTP/3. But the result was "Unable to connect". Meanwhile, the link https://localhost:8080/index.html for HTTP/2 was successful.

I noticed a suggestion in https://github.com/facebook/proxygen/issues/353 saying that I might need to set the same port for both HTTP versions. I also tried that but still Firefox could only connect to the server via HTTP/2.

I actually used quic-go to run HTTP/3 locally before, and it worked. So I don't think there was any problem with the browser.

lnicco commented 2 years ago

@chanh1964 thanks for reporting this. Browser learn about QUIC/HTTP3 via the Alt-Svc header returned on a response on a non-HTTP/3 request. The hq server does add the Alt-Svc header (you can grep for maybeAddAltSvcHeader to see where that gets added).

After using the same port for both http2 and http3 you may want to clear all the browser caches and state, restart the browser and try again.

As an alternative, Chrome has a commandline option to force QUIC. You can use --origin-to-force-quic-on=localhost:8443 to force QUIC to be used to hit the hq server.
I am less familiar with Firefox and I don't know if it has a similar flag.

chanh1964 commented 2 years ago

@lnicco Thank you for your response.

I have tried both suggestions but it still doesn't work, although I could see the Alt-Svc added to the header.

jbeshay commented 7 months ago

For Chrome, these are the parameters that had worked for me a while back:

--enable-quic --quic-version=h3 --ignore-certificate-errors-spki-list=<certificate fingerprint> --origin-to-force-quic-on=<server_address>:443

Feel free to re-open the issue if this is still not resolved.