温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/WebSocketOptions
点击访问原文链接

Bun.WebSocketOptions TypeScript type alias | API Reference | Bun

Bun.WebSocketOptions TypeScript type alias | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/Bun/WebSocketOptionsTWebSocketOptions

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/WebSocketOptionsTWebSocketOptions

type

WebSocketOptionstype WebSocketOptions = WebSocketOptionsProtocolsOrProtocol & WebSocketOptionsTLS & WebSocketOptionsHeaders & WebSocketOptionsProxy & WebSocketOptionsCompression

Constructor options for the Bun.WebSocket client

Referenced typestype WebSocketOptionsProtocolsOrProtocol = { protocols: string | string[] } | { protocol: string }type WebSocketOptionsTLS = tls?: TLSOptions

Options for the TLS connection.

Supports full TLS configuration including custom CA certificates, client certificates, and other TLS settings (same as fetch).

// Using BunFile for certificates
const ws = new WebSocket("wss:http://example.com", {
tls: {
ca: Bun.file("./ca.pem")
}
});

// Using Buffer
const ws = new WebSocket("wss:http://example.com", {
tls: {
ca: fs.readFileSync("./ca.pem")
}
});
type WebSocketOptionsHeaders = headers?: OutgoingHttpHeaders

Headers to send to the server

type WebSocketOptionsProxy = proxy?: string | { headers: OutgoingHttpHeaders | Headers; url: string }

HTTP proxy to use for the WebSocket connection.

Can be a string URL or an object with url and optional headers.

// String format
const ws = new WebSocket("wss:http://example.com", {
proxy: "http://proxy.example.com:8080"
});

// With credentials
const ws = new WebSocket("wss:http://example.com", {
proxy: "http://user:pass@proxy.example.com:8080"
});

// Object format with custom headers
const ws = new WebSocket("wss:http://example.com", {
proxy: {
url: "http://proxy.example.com:8080",
headers: {
"Proxy-Authorization": "Bearer token"
}
}
});
type WebSocketOptionsCompression = perMessageDeflate?: boolean

Whether to offer the permessage-deflate extension in the WebSocket upgrade request. Pass false to suppress the Sec-WebSocket-Extensions header entirely — matching the ws package's perMessageDeflate: false option.

Defaults to true (the upgrade request advertises permessage-deflate; client_max_window_bits). Any falsy value (false, null, 0, "", explicit undefined) disables the offer.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Bun.WebSocketOptions TypeScript type alias | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    Constructor options for the `Bun.WebSocket` client