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

shot

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shot - npm Package Compare versions

Comparing version 1.5.3 to 1.6.0

12

lib/index.js

@@ -21,3 +21,3 @@ // Load modules

// options: method, url, payload, headers
// options: method, url, payload, headers, remoteAddress

@@ -52,2 +52,6 @@ var url = options.url;

this.connection = {
remoteAddress: options.remoteAddress || '127.0.0.1'
};
// Use _shot namespace to avoid collision with Node

@@ -260,5 +264,5 @@

var parts = header.split(':');
if (parts.length === 2) {
response._headers[parts[0].trim().toLowerCase()] = parts[1].trim();
var headerParts = header.split(':');
if (headerParts.length === 2) {
response._headers[headerParts[0].trim().toLowerCase()] = headerParts[1].trim();
}

@@ -265,0 +269,0 @@ });

{
"name": "shot",
"description": "Injects a fake HTTP request/response into a node HTTP server",
"version": "1.5.3",
"version": "1.6.0",
"repository": "git://github.com/hapijs/shot",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

@@ -8,5 +8,5 @@ ![shot Logo](https://raw.github.com/hapijs/shot/master/images/shot.png)

Lead Maintainer: [Eran Hammer](https://github.com/hueniverse)
Lead Maintainer: [Matt Harrison](https://github.com/mtharrison)
For example:
## Example

@@ -47,1 +47,29 @@ ```javascript

Note how `server.listen` is never called.
### `Shot.inject(dispatchFunc, options, callback)`
Injects a fake request into an HTTP server.
- `dispatchFunc` - listener function. The same as you would pass to `Http.createServer` when making a node HTTP server. Has the signature `function (req, res)` where:
- `req` - a simulated request object. Inherits from `Stream.Readable`.
- `res` - a simulated response object. Inherits from node's `Http.ServerResponse`.
- `options` - request options object where:
- `url` - a string specifying the request URL.
- `method` - a string specifying the HTTP request method, defaulting to `'GET'`.
- `headers` - an optional object containing request headers.
- `remoteAddress` - an optional string specifying the client remote address. Defaults to `'127.0.0.1'`.
- `payload` - an optional request payload. Can be a string, Buffer or object.
- `simulate` - an object containing flags to simulate various conditions:
- `end` - indicates whether the request will fire an `end` event. Defaults to `undefined`, meaning an `end` event will fire.
- `split` - indicates whether the request payload will be split into chunks. Defaults to `undefined`, meaning payload will not be chunked.
- `error` - whether the request will emit an `error` event. Defaults to `undefined`, meaning no `error` event will be emitted. If set to `true`, the emitted error will have a message of `'Simulated'`.
- `close` - whether the request will emit a `close` event. Defaults to `undefined`, meaning no `close` event will be emitted.
- `callback` - the callback function using the signature `function (res)` where:
- `res` - a response object where:
- `raw` - an object containing the raw request and response objects where:
- `req` - the simulated request object.
- `req` - the simulated response object.
- `headers` - an object containing the response headers.
- `statusCode` - the HTTP status code.
- `payload` - the payload as a UTF-8 encoded string.
- `rawPayload` - the raw payload as a Buffer.

@@ -81,2 +81,32 @@ // Load modules

it('passes remote address', function (done) {
var dispatch = function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(req.connection.remoteAddress);
};
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', remoteAddress: '1.2.3.4' }, function (res) {
expect(res.payload).to.equal('1.2.3.4');
done();
});
});
it('passes localhost as default remote address', function (done) {
var dispatch = function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(req.connection.remoteAddress);
};
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' }, function (res) {
expect(res.payload).to.equal('127.0.0.1');
done();
});
});
it('optionally accepts an object as url', function (done) {

@@ -83,0 +113,0 @@

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