大网数据广告活动
Web 标准与前端开发

WebTransport: responseHeaders property

· 52CE 我爱测

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.

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

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。