Comparing version 0.20.1 to 0.20.2
@@ -115,2 +115,4 @@ "use strict"; | ||
this._addRules = (rules, reset = false) => __awaiter(this, void 0, void 0, function* () { | ||
if (!this.mockServerConfig) | ||
throw new Error('Cannot add rules before the server is started'); | ||
// Backward compat: make Add/SetRules work with servers that only define reset & addRule (singular). | ||
@@ -117,0 +119,0 @@ // Adds a small risk of odd behaviour in the gap between reset & all the rules being added, but it |
@@ -7,19 +7,2 @@ /// <reference types="node" /> | ||
import { CAOptions } from '../util/tls'; | ||
declare module "net" { | ||
interface Socket { | ||
upstreamEncryption?: boolean; | ||
encrypted?: boolean; | ||
clientErrorInProgress?: { | ||
rawPacket?: Buffer; | ||
}; | ||
__httpPeekedData?: Buffer; | ||
} | ||
} | ||
declare module "tls" { | ||
interface TLSSocket { | ||
servername?: string; | ||
initialRemoteAddress?: string; | ||
tlsSetupCompleted?: true; | ||
} | ||
} | ||
export declare type ComboServerOptions = { | ||
@@ -26,0 +9,0 @@ debug: boolean; |
@@ -149,3 +149,4 @@ "use strict"; | ||
ca: generatedCert.ca | ||
}) | ||
}), | ||
ALPNProtocols: ['http/1.1'] | ||
}); | ||
@@ -152,0 +153,0 @@ // Wait for: |
@@ -296,2 +296,6 @@ "use strict"; | ||
req.protocol = socket instanceof tls_1.TLSSocket ? "https" : "http"; // Wild guess really | ||
// For TLS sockets, we default the hostname to the name given by SNI. Might be overridden | ||
// by the URL or Host header later, if available. | ||
if (socket instanceof tls_1.TLSSocket) | ||
req.hostname = socket.servername; | ||
const lines = splitBuffer(input, '\r\n'); | ||
@@ -338,3 +342,3 @@ const requestLine = lines[0].slice(0, lines[0].length).toString('ascii'); | ||
} | ||
else { | ||
else if (parsedUrl.hostname) { | ||
req.hostname = parsedUrl.hostname; | ||
@@ -347,4 +351,5 @@ } | ||
else { | ||
// URI is relative - add the host | ||
req.url = `${req.protocol}://${req.hostname}${rawUri}`; | ||
// URI is relative (or invalid) and we have a host: use it | ||
req.url = `${req.protocol}://${req.hostname}${rawUri.startsWith('/') ? '' : '/' // Add a slash if the URI is garbage | ||
}${rawUri}`; | ||
} | ||
@@ -351,0 +356,0 @@ } |
{ | ||
"name": "mockttp", | ||
"version": "0.20.1", | ||
"version": "0.20.2", | ||
"description": "Mock HTTP server for testing HTTP clients and stubbing webservices", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -127,3 +127,3 @@ # Mockttp [![Travis Build Status](https://img.shields.io/travis/httptoolkit/mockttp.svg)](https://travis-ci.org/httptoolkit/mockttp) [![Available on NPM](https://img.shields.io/npm/v/mockttp.svg)](https://npmjs.com/package/mockttp) [![Try Mockttp on RunKit](https://badge.runkitcdn.com/mockttp.svg)](https://npm.runkit.com/mockttp) | ||
* [In-depth setup guide](docs/setup.md) | ||
* [API reference](https://httptoolkit.github.io/mockttp/modules/mockttp.html) | ||
* [API reference](https://httptoolkit.github.io/mockttp/interfaces/_mockttp_.mockttp.html) | ||
@@ -130,0 +130,0 @@ ## Credits |
@@ -314,2 +314,4 @@ /** | ||
private _addRules = async (rules: MockRuleData[], reset: boolean = false): Promise<MockedEndpoint[]> => { | ||
if (!this.mockServerConfig) throw new Error('Cannot add rules before the server is started'); | ||
// Backward compat: make Add/SetRules work with servers that only define reset & addRule (singular). | ||
@@ -316,0 +318,0 @@ // Adds a small risk of odd behaviour in the gap between reset & all the rules being added, but it |
@@ -12,40 +12,2 @@ import _ = require('lodash'); | ||
declare module "net" { | ||
interface Socket { | ||
// Have we CONNECT'd this socket to an upstream server? Defined if so. | ||
// Value tells you whether it started talking TLS or not afterwards. | ||
// If we somehow CONNECT repeatedly, this shows the state for the last time. | ||
upstreamEncryption?: boolean; | ||
// Normally only defined on TLSSocket, but useful to explicitly include here | ||
// Undefined on plain HTTP, 'true' on TLSSocket. | ||
encrypted?: boolean; | ||
// If there's a client error being sent, we track the corresponding packet | ||
// data on the socket, so that when it fires repeatedly we can combine them | ||
// into a single response & error event. | ||
clientErrorInProgress?: { rawPacket?: Buffer; } | ||
// Data that was peeked by httpolyglot, and thereby probably lost from the | ||
// HTTP parser errors, but which might be useful for debugging later | ||
__httpPeekedData?: Buffer; | ||
} | ||
} | ||
declare module "tls" { | ||
interface TLSSocket { | ||
// This is a real field that actually exists - unclear why it's not | ||
// in the type definitions. | ||
servername?: string; | ||
// We cache the initially set remote address on sockets, because it's cleared | ||
// before the TLS error callback is called, exactly when we want to read it. | ||
initialRemoteAddress?: string; | ||
// Marker used to detect whether client errors should be reported as TLS issues | ||
// (RST during handshake) or as subsequent client issues (RST during request) | ||
tlsSetupCompleted?: true; | ||
} | ||
} | ||
// Hardcore monkey-patching: force TLSSocket to link servername & remoteAddress to | ||
@@ -198,3 +160,4 @@ // sockets as soon as they're available, without waiting for the handshake to fully | ||
ca: generatedCert.ca | ||
}) | ||
}), | ||
ALPNProtocols: ['http/1.1'] | ||
}); | ||
@@ -201,0 +164,0 @@ |
@@ -366,2 +366,6 @@ /** | ||
// For TLS sockets, we default the hostname to the name given by SNI. Might be overridden | ||
// by the URL or Host header later, if available. | ||
if (socket instanceof TLSSocket) req.hostname = socket.servername; | ||
const lines = splitBuffer(input, '\r\n'); | ||
@@ -411,3 +415,3 @@ const requestLine = lines[0].slice(0, lines[0].length).toString('ascii'); | ||
req.hostname = Array.isArray(hostHeader) ? hostHeader[0] : hostHeader; | ||
} else { | ||
} else if (parsedUrl.hostname) { | ||
req.hostname = parsedUrl.hostname; | ||
@@ -420,4 +424,6 @@ } | ||
} else { | ||
// URI is relative - add the host | ||
req.url = `${req.protocol}://${req.hostname}${rawUri}`; | ||
// URI is relative (or invalid) and we have a host: use it | ||
req.url = `${req.protocol}://${req.hostname}${ | ||
rawUri.startsWith('/') ? '' : '/' // Add a slash if the URI is garbage | ||
}${rawUri}`; | ||
} | ||
@@ -424,0 +430,0 @@ } catch (e) {} |
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
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
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
657604
136
11983