How to use the http-proxy.buffer 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 codice / ddf / ui / packages / ui / server-impl.js View on Github external
server.requestProxy = function(req, res) {
  'use strict'

  req.url = 'https://localhost:8993' + req.url
  var urlObj = URL.parse(req.url)
  req.url = urlObj.path
  // Buffer requests so that eventing and async methods still work
  // https://github.com/nodejitsu/node-http-proxy#post-requests-and-buffering
  var buffer = httpProxy.buffer(req)
  console.log('Proxying Request "' + req.url + '"')

  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

  proxy.proxyRequest(req, res, {
    host: urlObj.hostname,
    port: urlObj.port || 80,
    buffer: buffer,
    changeOrigin: true,
    secure: false,
    target: {
      https: true,
    },
  })
}
github codice / ddf / ui / packages / security-handler-guest / server-impl.js View on Github external
server.requestProxy = function(req, res) {
  'use strict'

  req.url = 'http://localhost:8181' + req.url
  var urlObj = URL.parse(req.url)
  req.url = urlObj.path
  // Buffer requests so that eventing and async methods still work
  // https://github.com/nodejitsu/node-http-proxy#post-requests-and-buffering
  var buffer = httpProxy.buffer(req)
  console.log('Proxying Request "' + req.url + '"')

  proxy.proxyRequest(req, res, {
    host: urlObj.hostname,
    port: urlObj.port || 80,
    buffer: buffer,
    changeOrigin: true,
  })
}
github FriendCode / loadfire / lib / patterns / base.js View on Github external
BasePattern.prototype.handleWs = function (req, socket, head) {
    var backend = this.pickTreat(req);

    console.log('WEBSOCKET', backend);

    // Proxy the WebSocket request to the backend
    var proxy = new httpProxy.HttpProxy({
        target: {
            host: backend.host,
            port: backend.port
        }
    });
    var buffer = httpProxy.buffer(socket);
    proxy.proxyWebSocketRequest(req, socket, head, buffer);
};
github rSimulate / WebHexPlanet / web.js View on Github external
app.all('/*', function(request, response, next) {
        // find a simulation (if any) that contains the requested url
        console.log(request.method.toString() + ' ' + request.originalUrl);
        var buffer = httpProxy.buffer(request);
        db.collection('simulations').find({
            forwardedPaths: {'$elemMatch': {originalUrl: request.originalUrl}}}, {
            'forwardedPaths.$':1}).toArray(function(err, simulations) {
            if (err) {
                console.log(err);
                response.send(500);
            } else if (simulations.length == 0) {
                next();
            } else {
                var simulation = simulations[0];
                console.log(simulation);
                // parse the destination url
                var destUrl = url.parse(simulation.forwardedPaths[0].dest);
                // perform any url substitution
                request.path = destUrl.path;
                console.log('Forwarding request to ' + destUrl.hostname + ':' + destUrl.port);
github codice / ddf / ui / packages / catalog-admin-module-sources / server-impl.js View on Github external
server.requestProxy = function(req, res) {
  'use strict'

  req.url = 'https://localhost:8993' + req.url
  var urlObj = URL.parse(req.url)
  req.url = urlObj.path
  // Buffer requests so that eventing and async methods still work
  // https://github.com/nodejitsu/node-http-proxy#post-requests-and-buffering
  var buffer = httpProxy.buffer(req)
  console.log('Proxying Request "' + req.url + '"')

  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
  proxy.proxyRequest(req, res, {
    host: urlObj.hostname,
    port: urlObj.port || 80,
    buffer: buffer,
    changeOrigin: true,
    secure: false,
    target: {
      https: true,
    },
  })
}
github equiet / recognizer / src / proxy / middleware-proxy.js View on Github external
return function (req, res, next) {
    if (req.url.indexOf("public") !== -1) {
      var modifiedUrl = req.url.replace("/public", "");
      var fullURL = "http://" + req.headers.host + modifiedUrl;

      res.writeHead(302, { Location: fullURL });
      res.end();

      return;
    }

    var buffer = httpProxy.buffer(req);
    var _process = false;
    var _contentType;
    var _code, _headers;
    var _content = '';

    var _writeHead = res.writeHead;
    res.writeHead = function (code, headers) {
      _contentType = (headers['content-type'] || '').split(";")[0];
      _process = options.accept(req, _contentType);
      if (_process) {
        _code = code;
        _headers = headers;
      } else {
        _writeHead.apply(res, arguments);
      }
    };
github ngnjs / NGN / lib / web / Proxy.js View on Github external
var vh = me.vhost[port][url.hostname.toLowerCase()] || me.getVirtualHostByAlias(port,url.hostname.toLowerCase());
					
					if (!vh) {
						console.log(port,url,me.vhost);
						_res.writeHead(502);
	  					_res.end();
						return;
					}
					
					var target 	= vh.getTarget(_req),
						dest = require('url').parse('http'+''+'://'+target);
					
					proxy.proxyRequest(_req,_res,{
						host:	dest.hostname.toLowerCase(),
						port:	parseInt(dest.port||80),
						buffer:	prx.buffer(_req)
					});
					
				});
github odoe / agsnode-dev / app.js View on Github external
app.all('/proxy', function (req, res) {
        var buffer,
        url_,
        _query,
        _query_url,
        full_url,
        clean_url;

        /*
        * Apparently need this buffer because
        * express turns a POST body response
        * into an object.
        **/
        buffer = httpProxy.buffer(req);
        url_ = req.url.split('?')[1];
        _query = req.url.split('?')[2];
        _query_url = '';
        if (typeof _query !== 'undefined') {
            _query_url = '?' + _query;
        }
        full_url = url_ + _query_url;
        req.url = full_url;
        clean_url = url.parse(url_);

        proxy.proxyRequest(req, res, {
            host: clean_url.host,
            port: 80,
            buffer: buffer
        });
github colinmollenhour / node-caching-proxy / lib / caching-proxy.js View on Github external
init: function(req, res) {
    req.proxyRequest = this;
    this.protocol = req.isSpdy ? 'https' : (req.connection.pair ? 'https' : 'http');
    this.uri = this.protocol+'://'+req.headers.host+req.url;
    this.request = req;
    this.response = res;
    this.proxyEventBuffer = httpProxy.buffer(req);
    this.cacheKey = null;
    this.chunkCache = [];
    this.proxied = false;
    this.revalidate = false;
    this.candidates = null;
    this.selecting = null;
    ProxyRequest.count++;
  },
github LockerProject / Locker / Ops / webservice.js View on Github external
} else {
                fs.stat(path.join(lconfig.lockerDir, info.srcdir, fileUrl.pathname), function(err, stats) {
                    if (!err && (stats.isFile() || stats.isDirectory())) {
                        res.sendfile(path.join(lconfig.lockerDir, info.srcdir, fileUrl.pathname));
                    } else {
                        logger.warn("Could not find " + path.join(lconfig.lockerDir, info.srcdir, fileUrl.pathname))
                        res.send(404);
                    }
                });
            }
        });
        logger.silly("Sent static file " + path.join(lconfig.lockerDir, info.srcdir, "static", fileUrl.pathname));
    } else {
        if (!serviceManager.isRunning(id)) {
            logger.info("Having to spawn " + id);
            var buffer = httpProxy.buffer(req);
            serviceManager.spawn(id,function(){
                proxied(method, info, ppath, req, res, buffer);
            });
        } else {
            proxied(method, info, ppath, req, res);
        }
    }
    logger.silly("Proxy complete");
};