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

shot

Package Overview
Dependencies
Maintainers
4
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 3.4.2 to 3.5.2

LICENSE.md

5

lib/index.js
'use strict';
// Load modules
const Hoek = require('hoek');
const Joi = require('joi');
const Request = require('./request');

@@ -11,4 +10,2 @@ const Response = require('./response');

// Declare internals
const internals = {};

@@ -15,0 +12,0 @@

7

lib/request.js
'use strict';
// Load modules
const Stream = require('stream');

@@ -10,4 +8,2 @@ const Url = require('url');

// Declare internals
const internals = {};

@@ -119,6 +115,7 @@

if (this._shot.isDone) {
/* $lab:coverage:off$ */
if (this._shot.simulate.end !== false) { // 'end' defaults to true
this.push(null);
}
/* $lab:coverage:on$ */
return;

@@ -125,0 +122,0 @@ }

'use strict';
// Load modules
const Http = require('http');

@@ -9,4 +7,2 @@ const Stream = require('stream');

// Declare internals
const internals = {};

@@ -21,3 +17,2 @@

this._shot = { headers: null, trailers: {}, payloadChunks: [] };
this._headers = {}; // This forces node@8 to always render the headers
this.assignSocket(internals.nullSocket());

@@ -35,5 +30,27 @@

// Find the headers object if one was provided. If a headers object is present, call setHeader()
// on the first valid header, and then break out of the loop and call writeHead(). By calling
// setHeader(), Node will materialize a headers object.
const headers = arguments[arguments.length - 1];
if (typeof headers === 'object' && headers !== null) {
const headerNames = Object.keys(headers);
for (let i = 0; i < headerNames.length; ++i) {
const name = headerNames[i];
try {
this.setHeader(name, headers[name]);
break;
}
catch (ignoreErr) { } // Let the real writeHead() handle errors.
}
}
const result = super.writeHead.apply(this, arguments);
this._shot.headers = Object.assign({}, this._headers); // Should be .getHeaders() since node v7.7
// $lab:coverage:off$
this._shot.headers = typeof this.getHeaders === 'function' ? this.getHeaders() : Object.assign({}, this._headers);
// $lab:coverage:on$

@@ -52,2 +69,3 @@ // Add raw headers

return result;
}

@@ -58,3 +76,3 @@

super.write(data, encoding, callback);
this._shot.payloadChunks.push(new Buffer(data, encoding));
this._shot.payloadChunks.push(Buffer.from(data, encoding));
return true; // Write always returns false when disconnected

@@ -61,0 +79,0 @@ }

{
"name": "shot",
"description": "Injects a fake HTTP request/response into a node HTTP server",
"version": "3.4.2",
"version": "3.5.2",
"repository": "git://github.com/hapijs/shot",
"engines": {
"node": ">=6.0.0"
},
"main": "lib/index.js",

@@ -13,18 +16,15 @@ "keywords": [

],
"engines": {
"node": ">=4.5.0"
},
"dependencies": {
"hoek": "4.x.x",
"joi": "10.x.x"
"joi": "12.x.x"
},
"devDependencies": {
"code": "4.x.x",
"lab": "13.x.x"
"lab": "14.x.x"
},
"scripts": {
"test": "lab -a code -t 100 -L",
"test-cov-html": "lab -a code -r html -o coverage.html -L"
"test": "lab -a code -t 100 -L -l",
"test-cov-html": "lab -a code -r html -o coverage.html -L -l"
},
"license": "BSD-3-Clause"
"license": "SEE LICENSE IN LICENSE.md"
}

@@ -1,2 +0,2 @@

![shot Logo](https://raw.github.com/hapijs/shot/master/images/shot.png)
# shot

@@ -6,6 +6,4 @@ Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. Does not use a socket

[![Build Status](https://secure.travis-ci.org/hapijs/shot.png)](http://travis-ci.org/hapijs/shot)
[![Build Status](https://travis-ci.org/hapijs/shot.svg?branch=v3-commercial)](https://travis-ci.org/hapijs/shot)
Lead Maintainer: [Matt Harrison](https://github.com/mtharrison)
## Example

@@ -16,6 +14,5 @@

const Http = require('http');
const Shot = require('shot');
const Http = require("http");
const Shot = require("shot");
// Declare internals

@@ -25,21 +22,19 @@

internals.main = function () {
const dispatch = function (req, res) {
const reply = "Hello World";
res.writeHead(200, {
"Content-Type": "text/plain",
"Content-Length": reply.length,
});
res.end(reply);
};
const dispatch = function (req, res) {
const server = Http.createServer(dispatch);
const reply = 'Hello World';
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
res.end(reply);
};
const server = Http.createServer(dispatch);
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => {
console.log(res.payload);
});
Shot.inject(dispatch, { method: "get", url: "/" }, (res) => {
console.log(res.payload);
});
};
internals.main();

@@ -46,0 +41,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