WebTransport API
The responseHeaders read-only property of the WebTransport interface returns the HTTP headers from the server's response to the request that set up the session.
Value
A Headers object, or null if the session has not yet been established.
The returned object is immutable: calling methods that modify it, such as Headers.set() or Headers.append(), throws a TypeError.
Description
The session is set up using an extended CONNECT request.
The client can add custom headers to this request using the headers constructor option.
The server can include headers in its response to return application-specific information to the client, such as a session identifier.
The value is set before the WebTransport.ready promise fulfills.
The returned headers don't include WT-Protocol, which the server uses to indicate the application protocol it chose.
Use WebTransport.protocol to get the selected protocol instead.
Examples
Reading response headers
This example shows how you might send a custom header when setting up a session and then read a header that the server returns in its response.
const url = "https://example.com:4999/wt";
async function initTransport(url) {
const transport = new WebTransport(url, {
// Custom request headers
headers: { Authorization: "Bearer abc123" },
});
// responseHeaders is null until the session is established
console.log(transport.responseHeaders); // null
await transport.ready;
// Log all the response headers
for (const [name, value] of transport.responseHeaders) {
console.log(`${name}: ${value}`);
}
// Read a specific header
const sessionId = transport.responseHeaders.get("X-Session-Id");
console.log(`Session ID: ${sessionId}`);
return transport;
}
initTransport(url);
Specifications
Browser compatibility
See also
WebTransport()constructorheadersoption- WebTransport.protocol
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
