async function acceptWebSocket(
  req,
) {
  const { conn, headers, bufReader, bufWriter } = req;
  if (acceptable(req)) {
    const sock = new WebSocketImpl({
      conn,
      bufReader,
      bufWriter,
    });
    const secKey = headers.get("sec-websocket-key");
    if (typeof secKey !== "string") {
      throw new Error("sec-websocket-key is not provided");
    }
    const secAccept = createSecAccept(secKey);
    await writeResponse(bufWriter, {
      status: 101,
      headers: new Headers({
        Upgrade: "websocket",
        Connection: "Upgrade",
        "Sec-WebSocket-Accept": secAccept,
      }),
    });
    return sock;
  }
  throw new Error("request is not acceptable");
}
/** Upgrade given TCP connection into websocket connection */
Upgrade given TCP connection into websocket connection
Upgrade given TCP connection into websocket connection
async function acceptWebSocket(
  req,
) {
  const { conn, headers, bufReader, bufWriter } = req;
  if (acceptable(req)) {
    const sock = new WebSocketImpl({
      conn,
      bufReader,
      bufWriter,
    });
    const secKey = headers.get("sec-websocket-key");
    if (typeof secKey !== "string") {
      throw new Error("sec-websocket-key is not provided");
    }
    const secAccept = createSecAccept(secKey);
    await writeResponse(bufWriter, {
      status: 101,
      headers: new Headers({
        Upgrade: "websocket",
        Connection: "Upgrade",
        "Sec-WebSocket-Accept": secAccept,
      }),
    });
    return sock;
  }
  throw new Error("request is not acceptable");
}
async function acceptWebSocket ( req , ) { const { conn , headers , bufReader , bufWriter } = req ; if ( acceptable ( req ) ) { const sock = new WebSocketImpl ( { conn , bufReader , bufWriter , } ) ; const secKey = headers . get ( "sec-websocket-key" ) ; if ( typeof secKey !== "string" ) { throw new Error ( "sec-websocket-key is not provided" ) ; } const secAccept = createSecAccept ( secKey ) ; await writeResponse ( bufWriter , { status : 101 , headers : new Headers ( { Upgrade : "websocket" , Connection : "Upgrade" , "Sec-WebSocket-Accept" : secAccept , } ) , } ) ; return sock ; } throw new Error ( "request is not acceptable" ) ; }
Upgrade given TCP connection into websocket connection
Upgrade given TCP connection into websocket connection