node-mocks-http
Advanced tools
Comparing version 1.7.2 to 1.7.3
@@ -0,4 +1,11 @@ | ||
v 1.7.3 | ||
------- | ||
- Added `.range()` on a mocked request mimicking the [same function](http://expressjs.com/en/4x/api.html#req.range) on Express' request. [#175][175] | ||
[175]: https://github.com/howardabrams/node-mocks-http/pull/175 | ||
v 1.7.2 | ||
------- | ||
------- | ||
- Revert Turn mock request into a stream [#174][174] | ||
@@ -10,4 +17,4 @@ - Fix security issues reported by npm audit | ||
v 1.7.1 | ||
------- | ||
------- | ||
- Turn mock request into a stream [#169][169] | ||
@@ -27,7 +34,7 @@ - Added missing typings for "locals" & create a helper method to get locals [#170][170] | ||
- Add support for Buffer payload [#154][154] | ||
- Send request body/payload to trigger relevant events [#164][164] | ||
- Send request body/payload to trigger relevant events [#164][164] | ||
[154]: https://github.com/howardabrams/node-mocks-http/pull/154 | ||
[164]: https://github.com/howardabrams/node-mocks-http/pull/164 | ||
v 1.6.8 | ||
@@ -34,0 +41,0 @@ ------- |
@@ -36,2 +36,3 @@ 'use strict'; | ||
var accepts = require('accepts'); | ||
var parseRange = require('range-parser'); | ||
var EventEmitter = require('events').EventEmitter; | ||
@@ -195,2 +196,36 @@ var utils = require('./utils'); | ||
/** | ||
* Function: range | ||
* | ||
* Parse Range header field, capping to the given `size`. | ||
* | ||
* Unspecified ranges such as "0-" require knowledge of your resource length. In | ||
* the case of a byte range this is of course the total number of bytes. If the | ||
* Range header field is not given `undefined` is returned, `-1` when unsatisfiable, | ||
* and `-2` when syntactically invalid. | ||
* | ||
* When ranges are returned, the array has a "type" property which is the type of | ||
* range that is required (most commonly, "bytes"). Each array element is an object | ||
* with a "start" and "end" property for the portion of the range. | ||
* | ||
* The "combine" option can be set to `true` and overlapping & adjacent ranges | ||
* will be combined into a single range. | ||
* | ||
* NOTE: remember that ranges are inclusive, so for example "Range: users=0-3" | ||
* should respond with 4 users when available, not 3. | ||
* | ||
* @param {number} size | ||
* @param {object} [opts] | ||
* @param {boolean} [opts.combine=false] | ||
* @return {false|number|array} | ||
* @public | ||
*/ | ||
mockRequest.range = function(size, opts) { | ||
var range = mockRequest.get('Range'); | ||
if (!range) { | ||
return; | ||
} | ||
return parseRange(size, range, opts); | ||
}; | ||
/** | ||
* Function: param | ||
@@ -197,0 +232,0 @@ * |
@@ -491,3 +491,3 @@ 'use strict'; | ||
: Array.isArray(val) ? [prev].concat(val) | ||
: [prev, val]; | ||
: [prev, val]; | ||
} | ||
@@ -494,0 +494,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Mock 'http' objects for testing Express routing functions", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"homepage": "https://github.com/howardabrams/node-mocks-http", | ||
@@ -8,0 +8,0 @@ "bugs": { |
@@ -102,2 +102,4 @@ [![node-mocks-http logo][nmh-logo]][nmh-url] | ||
The object returned from this function also supports the [Express request](http://expressjs.com/en/4x/api.html#req) functions ([`.accepts()`](http://expressjs.com/en/4x/api.html#req.accepts), [`.is()`](http://expressjs.com/en/4x/api.html#req.is), [`.get()`](http://expressjs.com/en/4x/api.html#req.get), [`.range()`](http://expressjs.com/en/4x/api.html#req.range), etc.). Please send a PR for any missing functions. | ||
### .createResponse() | ||
@@ -104,0 +106,0 @@ |
71782
1709
239