text: "use strict";
  
  exports.__esModule = true;
  exports.respondOnWebSocket = respondOnWebSocket;
  
  var headerTransforms = _interopRequireWildcard(require("./header-transforms"));
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  
  /*eslint-disable no-unused-vars*/
  
  /*eslint-enable no-unused-vars*/
  function writeWebSocketHead(socket, destRes, headers) {
    const httpVersion = destRes.httpVersion,
          statusCode = destRes.statusCode,
          statusMessage = destRes.statusMessage;
    const resRaw = [`HTTP/${httpVersion} ${statusCode} ${statusMessage}`];
    const headersNames = Object.keys(headers);
  
    for (var _i = 0, _headersNames = headersNames; _i < _headersNames.length; _i++) {
      const headerName = _headersNames[_i];
      const headerValue = headers[headerName];
  
      if (Array.isArray(headerValue)) {
        for (var _iterator = headerValue, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
          var _ref;
  
          if (_isArray) {
            if (_i2 >= _iterator.length) break;
            _ref = _iterator[_i2++];
          } else {
            _i2 = _iterator.next();
            if (_i2.done) break;
            _ref = _i2.value;
          }
  
          const value = _ref;
          resRaw.push(headerName + ': ' + value);
        }
      } else resRaw.push(headerName + ': ' + headerValue);
    }
  
    resRaw.push('', '');
    socket.write(resRaw.join('\r\n'));
  }
  
  function respondOnWebSocket(ctx) {
    const headers = headerTransforms.forResponse(ctx);
    const destRes = ctx.destRes;
    writeWebSocketHead(ctx.res, destRes, headers);
    destRes.socket.pipe(ctx.res);
    ctx.res.pipe(destRes.socket);
  }