0.2.2 • Published 11 years ago

proxy-gremlin v0.2.2

Weekly downloads
1
License
-
Repository
github
Last release
11 years ago

Proxy Gremlin

Proxy Gremlin is a tiny middleware library that helps you to intercept and alter proxied responses. It is a middleware tool intended for use with node-http-proxy.

Example

var http = require('http')
  , proxy = require('http-proxy')
  , gremlin = require('proxy-gremlin')

http.createServer(function(req, res) { // start an http server

  // tell proxy-gremlin to buffer the response
  var buffer = new gremlin.Buffer(res)

  // set up a listener for when the proxied response is ready
  res.on('end', function() {

    console.log(buffer.headers)                  // log the headers
    console.log(buffer.encoding)                 // log the specified encoding
    console.log(buffer.getData())                // log buffered data

    buffer.headers['Content-Type'] = 'text/html' // change a header
    buffer.setData('Hello world')                // change the response's data
    buffer.send()                                // send the response
  })

  // Proxy the request
  proxy.proxyRequest(req, res, {
    host: proxiedHost,
    port: proxiedPort
  })

}).listen(8080)

License

MIT