Giter Site home page Giter Site logo

buffr's People

Contributors

abarre avatar jcrugzz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

fasterize

buffr's Issues

how to use buffr library in node-http-proxy to copy the request and after proxying it?

Hello!
I just found this library and I would like to ask you how to use it for the node-http-proxy....
Can you help me?
Thank you!!!!

var http = require('http'),
httpProxy = require('http-proxy'),
proxy = httpProxy.createProxyServer({});  
var miTarget='web:CountryName';
var inicio = '<'+miTarget+'>';
var fin = '</'+miTarget+'>';
var buffr = require('buffr');

var server = http.createServer(function(req, res) {
var miTag = '';
var buf = req.pipe(buffr());   // Here, using buffr library I should copy the req as I understand....

req.on('data', function (data) {
// here I recover the parameter I need...
 miTag=data.toString().split(inicio)[1].split(fin)[0];

});

 req.on('end', function () {
 console.log('miTag:'+miTag);
  // After I got the parameter I want to proxy to a server depending on the parameter's value....
  if(miTag=='Portugal') {
   proxy.web(req, res, {target: 'http://www.webservicex.net'});
  }
    else {
    proxy.web(req, res, {target: 'http://other/host'}); 
  }
    });     
});

console.log("listening on port 80")
server.listen(80);

Is it possible to add a parameter (tag) to the buffer before to be sent?

Dear Jarrett,

I really appreciate your great support!

Look, I would like to modify the data before to be sent to the target. Let's suppose that I need to add a new field in the data: <extra_field>100</extra_field>

Should I do it using the buffer?

Here goes my code:

var http = require('http'),
httpProxy = require('http-proxy'),
proxy = httpProxy.createProxyServer({});
var miTarget='web:CountryName';
var inicio = '<'+miTarget+'>';
var fin = '</'+miTarget+'>';
var buffr = require('buffr');

var server = http.createServer(function(req, res) {
var miTag = '';
var buf = req.pipe(buffr()); // Here, using buffr library I should copy the req as I understand....
buf.extra_field='100' // should I add the new parameter here?

req.on('data', function (data) {
// here I recover the parameter I need...
miTag=data.toString().split(inicio)[1].split(fin)[0];

});

req.on('end', function () {
console.log('miTag:'+miTag);
// After I got the parameter I want to proxy to a server depending on the parameter's value....
if(miTag=='Portugal') {
proxy.web(req, res, {target: 'http://www.webservicex.net',buffer:buf});
}
else {
proxy.web(req, res, {target: 'http://other/host',buffer:buf});
}
});
});

console.log("listening on port 80")
server.listen(80);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.