How to use the http-proxy/lib/http-proxy/passes/ws-incoming.stream function in http-proxy

To help you get started, we’ve selected a few http-proxy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github embark-framework / embark / packages / embark-blockchain-process / src / httpProxyOverride.js View on Github external
/* global require */

const http = require('http');
const https = require('https');
const httpProxyWsIncoming = require('http-proxy/lib/http-proxy/passes/ws-incoming');
const common = require('http-proxy/lib/http-proxy/common');

const CRLF = '\r\n';

httpProxyWsIncoming.stream = (req, socket, options, head, server, cb) => {
  const createHttpHeader = function(line, headers) {
    return Object.keys(headers).reduce(function (head, key) {
      const value = headers[key];
      if (!Array.isArray(value)) {
        head.push(`${key}: ${value}`);
        return head;
      }
      for (let i = 0; i < value.length; i++) {
        head.push(`${key}: ${value[i]}`);
      }
      return head;
    }, [line])
      .join(CRLF) + `${CRLF}${CRLF}`;
  };

  common.setupSocket(socket);