markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
564 stars 164 forks source link

Chapter 13 HTTP/3 issue #15

Closed Pip1987 closed 5 months ago

Pip1987 commented 7 months ago

Hi I'm following along with http/3 and I got everything set up. Chrome debug tools show h3 under Alt-Svc but the console shows HTTP/2 GET message. Is this a bug, or did I miss something I do have the code snippet in my Program.cs along with the using Microsoft.AspNetCore.Server.Kestrel.Core; I'm also running Windows 11.

builder.WebHost.ConfigureKestrel((context, options) =>
{
    options.ConfigureEndpointDefaults(listenOptions =>
    {
        listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
        listenOptions.UseHttps(); // HTTP/3 requires secure connections.
    });
});

http3chromeImage http3consoleImage

markjprice commented 7 months ago

Hmmmm, it could just be the server-side outputting the wrong information. I'll need to investigate. I've got deadlines coming up so I might not get to this for a few weeks.

Pip1987 commented 7 months ago

No problem. I thought it was weird and would mention it incase I did something wrong.

Pip1987 commented 7 months ago

To add more information for your investigation, I just set up the API service to request using Http/3 and it's the same thing, it is failing over to http/2.

RTDMakler commented 5 months ago

I faced with the same problem. Moreover I had one more issue with redirection, although I ran program with "https" (& chromium browser cent) VS2022 opened in browser "http://localhost:5130/" . Configuration:

builder.WebHost.ConfigureKestrel((context, options) =>
{
  options.ConfigureEndpointDefaults(listenOptions =>
  {
    listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
    listenOptions.UseHttps();
  });
});

If you decide to choose just Http3 then there is no effect, nothing will open.

listenOptions.Protocols = HttpProtocols.Http3;

After some research I found solution: https://github.com/dotnet/AspNetCore.Docs/issues/23700. The main idea is "that browsers won't do HTTP/3 with self-signed certs like the Kestrel dev cert". So the solution is to open by terminal the link with special attributes that ignores certificate. For me the command is

& "C:\Users\RTD\AppData\Local\CentBrowser\Application\chrome.exe" '--user-data-dir=c:\Temp\chrometemp' --no-proxy-server --enable-quic --origin-to-force-quic-on=localhost:5131 --host-resolver-rules='MAP localhost:5131 127.0.0.1:5131' --ignore-certificate-errors-spki-list=a8030c5bb13ac23db4e29fb9fd05da22d2133681 --log-net-log=c:\Temp\chrometemp\chrome.json --net-log-capture-mode=IncludeSensitive --quic-version=h3 https://localhost:5131/

You need to change your browser location, website port(if your port for https is not 5131) and certificate number

--ignore-certificate-errors-spki-list=a8030c5bb13ac23db4e29fb9fd05da22d2133681

In order to get it:

  1. Run program.
  2. Enter https://localhost:5131/. Note: don't use only http3 in listenOptions.Protocols = HttpProtocols.Http3; when you try to get cetificate number or you can't go to the next step.
  3. Click a lock left from link -> connection -> certificate-> details -> find thumbprint number.
  4. Open terminal and pass the command above with your parameters.

But with this approach you need each time you run app enter a command in order to avoid certificate restrictions.

markjprice commented 5 months ago

Thanks, RTD! That's really helpful. :)

I've added this as an item here: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/errata.md#page-694---exercise-133--enabling-http3-and-request-decompression-support