I'll be back once I have observed the server side variables under different connection scenarios.
Let's get some basics out of the way first. I have set up a server to do some testing with, and have been working with it for the last couple of days.
Code:
$ curl --http3 -k --head https://localhost
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 10261 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
HTTP/3 200
content-type: text/html
last-modified: Fri, 09 Aug 2024 22:30:50 GMT
etag: "2815-66b6989a-b720f36db1479b76;;;"
accept-ranges: bytes
content-length: 10261
date: Wed, 14 Aug 2024 19:22:39 GMT
server: LiteSpeed
alt-svc: h3=":443"; ma=2592000, h3-29=":443"; ma=2592000, h3-Q050=":443"; ma=2592000, h3-Q046=":443"; ma=2592000, h3-Q043=":443"; ma=2592000, quic=":443"; ma=2592000; v="43,46"
This confirms that I am running LiteSpeed, that I have functional TLS, and I listen to and accept HTTP/3 connections over QUIC.
I suppose Alt-Svc would be missing entirely when the connection is already h3...? Maybe I can be sure we're connected via h3 that way?
This is false. Alt-Svc header is still served for HTTP/3 connections, at the very least because it has "ma" values, meaning it is not persistent as served. The reason I did not see them is because browsers don't show complete response headers for cached requests, visible in curl though.
Code:
$_SERVER['SSL_PROTOCOL'] // QUIC
This is exactly what I was looking for, so thanks for that. I've been writing test scripts leveraging this for the last couple of days.
Essentially I expect the flow to be something like:
- the browser connects via h2 to the landing page
- Alt-Svc response header proposes h3
- JavaScript calls a page reload after a delay
- the browser is expected to connect via h3
- backend code detects h3 and responds with content submission form
- (otherwise the landing page with a page reload will repeat for some iterations until the browser jumps to h3)
So this seemed like a sound idea, but I only got this working on Firefox.
Firefox is a good sport about switching from h2 to h3 on a 30x status code redirect or a JavaScript reload.
Observe that h2 connection request got served a 301 status code by the script, and on the redirected request the h3 connection is served a happy 200 status code. This is how I envisioned this working.
But...
I get no love on Chrome. It doesn't want to connect over h3 to this server... I refresh many times, very rarely but sometimes it does connect over h3. Maybe 5% of the time. I don't understand how to make it more reliable or predicable, but that's mostly not a LiteSpeed question, probably, although Googling finds similar questions asked with no solution found.
I did read about the "winning the race" behavior in the past, where Chrome supposedly opens two connections simultaneously and looks to see which succeeds first. I did think about that scenario, where I thought maybe h2 responses could be intentionally delayed to make sure h3 always wins the race, but I have not been able to implement this successfully yet. Or it requires a more advanced webserver configuration, which would make it a LiteSpeed question.
Configuring ALPN did not produce the desired effect either.
I have not tried Safari yet either.