Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

response-spy

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

response-spy

Intercepts HTTP response headers && body (without any man-in-the-middle http proxy server)

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50
decreased by-40.48%
Maintainers
1
Weekly downloads
 
Created
Source
 _ __ ___  ___ _ __   ___  _ __  ___  ___        ___ _ __  _   _ 
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \      / __| '_ \| | | |
| | |  __/\__ \ |_) | (_) | | | \__ \  __/      \__ \ |_) | |_| |
|_|  \___||___/ .__/ \___/|_| |_|___/\___|      |___/ .__/ \__, |
              | |                                   | |     __/ |
              |_|                                   |_|    |___/ 

Node module for intercepting HTTP responses sent in your apps.

Example

var http = require('http');
var intercept = require('response-spy');

http.createServer(function(req, res) {
  // returns a readable stream with the response output as the data
  var stream = intercept(res);

  // You can also see the headers sent, uncomment below
  /*
  stream.on('headers', function(headers, statusCode) {
    // headers === Array || null (implicit headers)
    console.log('url: %s, headers: ', req.url, headers);
  });
  */

  stream.pipe(process.stdout);

  if (req.url === '/') {
    res.setHeader('X-Powered-By', 'alessioalex');
    res.writeHead(200, { 'Content-Type': 'text/html', 'X-Pid': 1239 });
    res.end('Hello world\n');
  } else if (req.url === '/pipe') {
    require('fs').createReadStream(__filename).pipe(res);
  } else if (req.url === '/implicit-headers') {
    res.end('go\n');
  } else {
    res.writeHead(404, { 'Connection': 'closed', 'Content-Type': 'text/html' });
    res.end('Page Not Found\n');
  }
}).listen(5000);
console.log('Ok good, now visit http://localhost:5000/ && http://localhost:5000/pipe');
console.log('.. and then check your terminal');

How does it work?

It overrides the OutgoingMessage native functions (write, writeHead, end, setHeader, removeHeader), without affecting your apps (the original functions will be called with the same params, these are just thin wrappers). With response-spy you practically get a ReadableStream from your response object.

Use cases

  • generating cache
  • traffic analysis
  • etc

License MIT

Keywords

FAQs

Package last updated on 10 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc