Comparing version 3.4.2 to 3.5.2
'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 @@ |
'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 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
269
11895
1
1
80
45
2
+ Added@hapi/address@1.0.1(transitive)
+ Addedjoi@12.1.1(transitive)
- Removedisemail@2.2.1(transitive)
- Removeditems@2.2.1(transitive)
- Removedjoi@10.6.0(transitive)
Updatedjoi@12.x.x