http-recorder

0.0.1 • Public • Published

http-recorder

A tool to record and play back raw http requests. Multiple requests over a single connection (Keep-Alive) are supported.

Usage

This module ships with a simple http-recorder command line tool that takes two optional arguments.

http-recorder $PORT $DIRECTORY

$PORT defaults to 8080 and $DIRECTORY defaults to process.cwd().

Once started, http-recorder listens for incoming connections, and stores the raw incoming http data in files named request_<id>.http. id is an integer starting at 1 that increments with each incoming request.

Alternatively, you can also use the module programatically.

var HttpRecorder = require('http-recorder');

var recorder = HttpRecorder.create(__dirname);
recorder.listen(1234);
recorder.on('record', function(record) {
  console.log('New record: %s', record.getPath());
});

Once you have one or more recorded http requests, you can use the HttpPlayer for playing them back.

var HttpPlayer = require('http-recorder').HttpPlayer;
var player = HttpPlayer.create(common.port);

player.add('request_1.http', 'request_2.http');

player.end(function(err) {
  if (err) {
    throw err;
  }
});

Please note: The player is a very dumb http client. When calling player.end(), it opens a single socket to the given port / host, and simply pipes all files passed to player.add() sequentially into it. You are responsible for figuring out if the host supports Keep-Alive or not.

What do with this?

This module is useful if you are tasked to write a http payload parser (like [formidable][]), and you want to start out by gathering a good set of test data that you can easily feed into your parser.

You may be able to do other things with it as well, but the module is not meant for recording and replaying user interactions (as that would likely require modifying the Host header for different environments).

License

http-recorder is licensed under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i http-recorder

Weekly Downloads

1

Version

0.0.1

License

none

Last publish

Collaborators

  • felixge