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.6.0 to 1.6.1

API.md

7

lib/index.js

@@ -44,9 +44,4 @@ // Load modules

this.headers['user-agent'] = this.headers['user-agent'] || 'shot';
this.headers.host = this.headers.host || uri.host || 'localhost';
if (uri.host &&
!this.headers.host) {
this.headers.host = uri.host;
}
this.connection = {

@@ -53,0 +48,0 @@ remoteAddress: options.remoteAddress || '127.0.0.1'

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

@@ -14,3 +14,3 @@ "main": "lib/index.js",

"engines": {
"node": ">=0.10.32"
"node": ">=0.10.40"
},

@@ -17,0 +17,0 @@ "dependencies": {

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

### `Shot.inject(dispatchFunc, options, callback)`
## API
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.
See the [API Reference](API.md)

@@ -111,2 +111,47 @@ // Load modules

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

@@ -113,0 +158,0 @@

Sorry, the diff of this file is not supported yet

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