How to use the http-proxy/lib/http-proxy/common.setupOutgoing 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
for (let i = 0; i < value.length; i++) {
        head.push(`${key}: ${value[i]}`);
      }
      return head;
    }, [line])
      .join(CRLF) + `${CRLF}${CRLF}`;
  };

  common.setupSocket(socket);

  if (head && head.length) socket.unshift(head);

  const protocol = common.isSSL.test(options.target.protocol) ? https : http;

  const proxyReq = protocol.request(
    common.setupOutgoing(options.ssl || {}, options, req)
  );

  // Enable developers to modify the proxyReq before headers are sent
  if (server) {
    server.emit('proxyReqWs', proxyReq, req, socket, options, head);
  }

  // Error Handler
  proxyReq.on('error', onOutgoingError);
  proxyReq.on('response', function (res) {
    // if upgrade event isn't going to happen, close the socket
    if (!res.upgrade) {
      const {httpVersion, statusCode, statusMessage, headers} = res;
      socket.write(createHttpHeader(
        `HTTP/${httpVersion} ${statusCode} ${statusMessage}`,
        headers
github h2non / rocky / lib / protocols / http / passes / replay.js View on Github external
function setRequestParams (req, opts) {
  const target = req.rocky.options.target || opts.target
  const url = parseUrl(target)
  const params = setupReq(opts.ssl || {}, opts, req)

  params.hostname = url.hostname
  params.port = url.port

  const forwardHost = opts.forwardHost
  if (typeof forwardHost === 'string') {
    params.headers.host = forwardHost
  } else if (forwardHost) {
    params.headers.host = url.host
  }

  if ((req.method === 'DELETE' || req.method === 'OPTIONS') && !req.headers['content-length']) {
    params.headers['content-length'] = '0'
  }

  if (opts.replayOriginalBody && req._originalBodyLength) {