Socket
Socket
Sign inDemoInstall

mockttp

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockttp - npm Package Compare versions

Comparing version 0.20.2 to 0.20.3

10

dist/mockttp.d.ts

@@ -358,8 +358,8 @@ import * as cors from 'cors';

* be sent to/via the server, to avoid storing all traffic in memory unnecessarily,
* if getSeenRequests will not be used. Traffic can still be captured live using
* .on('request') & .on('response'), this only disables the built-in persistence
* of that data.
* if getSeenRequests will not be used.
*
* Note that if this is set to true then getSeenRequests() will always return
* an empty array.
* If this is set to false then getSeenRequests() will always return
* an empty array. This only disables the built-in persistence of request data,
* so traffic can still be captured live or stored elsewhere using
* .on('request') & .on('response').
*/

@@ -366,0 +366,0 @@ recordTraffic?: boolean;

@@ -27,2 +27,3 @@ "use strict";

const fs_1 = require("../util/fs");
const util_1 = require("../util/util");
// An error that indicates that the handler is aborting the request.

@@ -59,3 +60,3 @@ // This could be intentional, or an upstream server aborting the request.

if (isSerializedBuffer(this.data)) {
this.data = new Buffer(this.data);
this.data = Buffer.from(this.data);
}

@@ -304,3 +305,3 @@ response.end(this.data || "");

// so we should fix the content length for you automatically.
return body.length.toString();
return util_1.byteLength(body).toString();
}

@@ -316,3 +317,3 @@ // There was a content length before, and you're replacing the headers entirely

if (lengthOverride === originalHeaders['content-length'] &&
lengthOverride !== body.length.toString() &&
lengthOverride !== util_1.byteLength(body).toString() &&
!mismatchAllowed // Set for HEAD responses

@@ -323,3 +324,3 @@ ) {

with mismatched values, which may be a mistake. The body contains
${body.length} bytes, whilst the header was set to ${lengthOverride}.
${util_1.byteLength(body)} bytes, whilst the header was set to ${lengthOverride}.
`);

@@ -326,0 +327,0 @@ }

@@ -19,2 +19,3 @@ "use strict";

const handlers_1 = require("./handlers");
const util_1 = require("../util/util");
/**

@@ -210,3 +211,3 @@ * @class MockRuleBuilder

'Content-Type': 'application/json',
'Content-Length': jsonData.length.toString()
'Content-Length': util_1.byteLength(jsonData).toString()
}, headers);

@@ -213,0 +214,0 @@ const rule = {

@@ -176,3 +176,3 @@ "use strict";

else if (encoding === 'br') {
return new Buffer(brotliDecompress(body));
return Buffer.from(brotliDecompress(body));
}

@@ -179,0 +179,0 @@ else if (encoding === 'amz-1.0') {

@@ -0,4 +1,6 @@

/// <reference types="node" />
export declare function nthIndexOf(input: string, matcher: string, n: number): number;
export declare function byteLength(input: string | Buffer): number;
export declare const isWorker: boolean;
export declare const isWeb: boolean;
export declare const isNode: string | false;

@@ -14,2 +14,16 @@ "use strict";

exports.nthIndexOf = nthIndexOf;
// Get the length of the given data in bytes, not characters.
// If that's a buffer, the length is used raw, but if it's a string
// it returns the length when encoded as UTF8.
function byteLength(input) {
if (typeof input === 'string') {
return exports.isNode
? Buffer.from(input, 'utf8').byteLength
: new Blob([input]).size;
}
else {
return input.length;
}
}
exports.byteLength = byteLength;
exports.isWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;

@@ -16,0 +30,0 @@ exports.isWeb = typeof Window !== 'undefined' && self instanceof Window;

{
"name": "mockttp",
"version": "0.20.2",
"version": "0.20.3",
"description": "Mock HTTP server for testing HTTP clients and stubbing webservices",

@@ -5,0 +5,0 @@ "main": "dist/main.js",

@@ -391,8 +391,8 @@ /**

* be sent to/via the server, to avoid storing all traffic in memory unnecessarily,
* if getSeenRequests will not be used. Traffic can still be captured live using
* .on('request') & .on('response'), this only disables the built-in persistence
* of that data.
* if getSeenRequests will not be used.
*
* Note that if this is set to true then getSeenRequests() will always return
* an empty array.
* If this is set to false then getSeenRequests() will always return
* an empty array. This only disables the built-in persistence of request data,
* so traffic can still be captured live or stored elsewhere using
* .on('request') & .on('response').
*/

@@ -399,0 +399,0 @@ recordTraffic?: boolean;

@@ -48,2 +48,3 @@ /**

} from "../types";
import { byteLength } from '../util/util';

@@ -113,3 +114,3 @@ // An error that indicates that the handler is aborting the request.

if (isSerializedBuffer(this.data)) {
this.data = new Buffer(<any> this.data);
this.data = Buffer.from(<any> this.data);
}

@@ -487,3 +488,3 @@

// so we should fix the content length for you automatically.
return body.length.toString();
return byteLength(body).toString();
}

@@ -502,3 +503,3 @@

lengthOverride === originalHeaders['content-length'] &&
lengthOverride !== body.length.toString() &&
lengthOverride !== byteLength(body).toString() &&
!mismatchAllowed // Set for HEAD responses

@@ -509,3 +510,3 @@ ) {

with mismatched values, which may be a mistake. The body contains
${body.length} bytes, whilst the header was set to ${lengthOverride}.
${byteLength(body)} bytes, whilst the header was set to ${lengthOverride}.
`);

@@ -512,0 +513,0 @@ }

@@ -50,2 +50,3 @@ /**

import { MaybePromise } from "../util/type-utils";
import { byteLength } from "../util/util";

@@ -304,3 +305,3 @@ /**

'Content-Type': 'application/json',
'Content-Length': jsonData.length.toString()
'Content-Length': byteLength(jsonData).toString()
}, headers);

@@ -307,0 +308,0 @@

@@ -207,3 +207,3 @@ /**

} else if (encoding === 'br') {
return new Buffer(brotliDecompress(body));
return Buffer.from(brotliDecompress(body));
} else if (encoding === 'amz-1.0') {

@@ -210,0 +210,0 @@ // Weird encoding used by some AWS requests, actually just unencoded JSON:

@@ -13,3 +13,16 @@ export function nthIndexOf(input: string, matcher: string, n: number) {

// Get the length of the given data in bytes, not characters.
// If that's a buffer, the length is used raw, but if it's a string
// it returns the length when encoded as UTF8.
export function byteLength(input: string | Buffer) {
if (typeof input === 'string') {
return isNode
? Buffer.from(input, 'utf8').byteLength
: new Blob([input]).size;
} else {
return input.length;
}
}
declare const WorkerGlobalScope: Function | undefined;

@@ -16,0 +29,0 @@ export const isWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc