v154 · webtransport headers

Reading the option

No server needed, and no waiting for a connection. Hand the constructor an options object whose members are getters that throw, and the ones this build actually knows about announce themselves — synchronously, before any network work begins.

Which members does this build read?

Running…

WebTransportOptions, member by member
memberread?what that means

The two control rows are what make the rest trustworthy. serverCertificateHashes has been in the dictionary since WebTransport shipped, so its getter must fire; definitelyNotAMember is invented, so it must not. If those two ever disagreed with expectation, every other row here would be meaningless.

And the response half

The request half is a dictionary member, so it takes a getter to see. The response half is a plain property, and a prototype simply has it or does not — here is the whole surface of WebTransport.prototype in this browser, with responseHeaders highlighted if present:

code path

// A getter that throws turns "was this member read?" into a question the
// constructor answers immediately, with no dependence on the return value.
function reads(member) {
  const sentinel = "PROBE_" + member;
  try {
    new WebTransport("https://127.0.0.1:44443/never", {
      get [member]() { throw new Error(sentinel); },
    });
    return false;                       // never read
  } catch (error) {
    return error.message === sentinel;  // read, and it was our throw
  }
}

// The response half needs no probe at all.
const hasResponseHeaders = "responseHeaders" in WebTransport.prototype;

see also