You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

mockttp

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.12.0 to 3.13.0

dist/util/url.d.ts

22

dist/rules/matchers.js

@@ -9,6 +9,6 @@ "use strict";

const types_1 = require("../types");
const url_1 = require("../util/url");
const request_utils_1 = require("../util/request-utils");
const serialization_1 = require("../serialization/serialization");
const body_serialization_1 = require("../serialization/body-serialization");
const normalize_url_1 = require("../util/normalize-url");
function unescapeRegexp(input) {

@@ -162,13 +162,13 @@ return input.replace(/\\\//g, '/');

}
(0, normalize_url_1.normalizeUrl)(this.path); // Fail if URL can't be normalized
(0, url_1.normalizeUrl)(this.path); // Fail if URL can't be normalized
}
matches(request) {
const expectedUrl = (0, normalize_url_1.normalizeUrl)(this.path);
const reqUrl = (0, normalize_url_1.normalizeUrl)(request.url);
const expectedUrl = (0, url_1.normalizeUrl)(this.path);
const reqUrl = (0, url_1.normalizeUrl)(request.url);
// reqUrl is always absolute, expectedUrl can be absolute, relative or protocolless-absolute
if ((0, request_utils_1.isRelativeUrl)(expectedUrl)) {
if ((0, url_1.isRelativeUrl)(expectedUrl)) {
// Match the path only, for any host
return (0, request_utils_1.getPathFromAbsoluteUrl)(reqUrl) === expectedUrl;
return (0, url_1.getPathFromAbsoluteUrl)(reqUrl) === expectedUrl;
}
else if ((0, request_utils_1.isAbsoluteUrl)(expectedUrl)) {
else if ((0, url_1.isAbsoluteUrl)(expectedUrl)) {
// Full absolute URL: match everything

@@ -179,3 +179,3 @@ return reqUrl === expectedUrl;

// Absolute URL with no protocol
return (0, request_utils_1.getUrlWithoutProtocol)(reqUrl) === expectedUrl;
return (0, url_1.getUrlWithoutProtocol)(reqUrl) === expectedUrl;
}

@@ -196,4 +196,4 @@ }

matches(request) {
const absoluteUrl = (0, normalize_url_1.normalizeUrl)(request.url);
const urlPath = (0, request_utils_1.getPathFromAbsoluteUrl)(absoluteUrl);
const absoluteUrl = (0, url_1.normalizeUrl)(request.url);
const urlPath = (0, url_1.getPathFromAbsoluteUrl)(absoluteUrl);
// Test the matcher against both the path alone & the full URL

@@ -217,3 +217,3 @@ const urlMatcher = new RegExp(this.regexSource, this.regexFlags);

matches(request) {
const absoluteUrl = (0, normalize_url_1.normalizeUrl)(request.url);
const absoluteUrl = (0, url_1.normalizeUrl)(request.url);
// Test the matcher against the full URL

@@ -220,0 +220,0 @@ const urlMatcher = new RegExp(this.regexSource, this.regexFlags);

@@ -5,2 +5,3 @@ /// <reference types="node" />

import { Readable } from 'stream';
import { Operation as JsonPatchOperation } from 'fast-json-patch';
import { Headers, Trailers, CompletedRequest, CompletedBody, Explainable, RawHeaders } from "../../types";

@@ -375,4 +376,7 @@ import { MaybePromise, Replace } from '../../util/type-utils';

* A JSON object which will be merged with the real request body. Undefined values
* will be removed. Any requests which are received with an invalid JSON body that
* match this rule will fail.
* will be removed, and other values will be merged directly with the target value
* recursively.
*
* Any requests which are received with an invalid JSON body that match this rule
* will fail.
*/

@@ -383,2 +387,10 @@ updateJsonBody?: {

/**
* A series of operations to apply to the request body in JSON Patch format (RFC
* 6902).
*
* Any requests which are received with an invalid JSON body that match this rule
* will fail.
*/
patchJsonBody?: Array<JsonPatchOperation>;
/**
* Perform a series of string match & replace operations on the request body.

@@ -428,4 +440,7 @@ *

* A JSON object which will be merged with the real response body. Undefined values
* will be removed. Any responses which are received with an invalid JSON body that
* match this rule will fail.
* will be removed, and other values will be merged directly with the target value
* recursively.
*
* Any responses which are received with an invalid JSON body that match this rule
* will fail.
*/

@@ -436,2 +451,10 @@ updateJsonBody?: {

/**
* A series of operations to apply to the response body in JSON Patch format (RFC
* 6902).
*
* Any responses which are received with an invalid JSON body that match this rule
* will fail.
*/
patchJsonBody?: Array<JsonPatchOperation>;
/**
* Perform a series of string match & replace operations on the response body.

@@ -438,0 +461,0 @@ *

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

const common_tags_1 = require("common-tags");
const fast_json_patch_1 = require("fast-json-patch");
const request_utils_1 = require("../../util/request-utils");

@@ -211,2 +212,3 @@ const buffer_utils_1 = require("../../util/buffer-utils");

options.transformRequest.updateJsonBody,
options.transformRequest.patchJsonBody,
options.transformRequest.matchReplaceBody

@@ -216,2 +218,7 @@ ].filter(o => !!o).length > 1) {

}
if (options.transformRequest.patchJsonBody) {
const validationError = (0, fast_json_patch_1.validate)(options.transformRequest.patchJsonBody);
if (validationError)
throw validationError;
}
this.transformRequest = options.transformRequest;

@@ -236,2 +243,3 @@ }

options.transformResponse.updateJsonBody,
options.transformResponse.patchJsonBody,
options.transformResponse.matchReplaceBody

@@ -241,2 +249,7 @@ ].filter(o => !!o).length > 1) {

}
if (options.transformResponse.patchJsonBody) {
const validationError = (0, fast_json_patch_1.validate)(options.transformResponse.patchJsonBody);
if (validationError)
throw validationError;
}
this.transformResponse = options.transformResponse;

@@ -243,0 +256,0 @@ }

@@ -15,2 +15,4 @@ "use strict";

const typed_error_1 = require("typed-error");
const fast_json_patch_1 = require("fast-json-patch");
const url_1 = require("../../util/url");
const request_utils_1 = require("../../util/request-utils");

@@ -293,3 +295,3 @@ const header_utils_1 = require("../../util/header-utils");

let headers = (0, header_utils_1.rawHeadersToObject)(rawHeaders);
const { replaceMethod, updateHeaders, replaceHeaders, replaceBody, replaceBodyFromFile, updateJsonBody, matchReplaceBody } = this.transformRequest;
const { replaceMethod, updateHeaders, replaceHeaders, replaceBody, replaceBodyFromFile, updateJsonBody, patchJsonBody, matchReplaceBody } = this.transformRequest;
if (replaceMethod) {

@@ -319,6 +321,7 @@ method = replaceMethod;

const { body: realBody } = await (0, request_utils_1.waitForCompletedRequest)(clientReq);
if (await realBody.getJson() === undefined) {
throw new Error("Can't transform non-JSON request body");
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't update JSON in non-JSON request body");
}
const updatedBody = _.mergeWith(await realBody.getJson(), updateJsonBody, (_oldValue, newValue) => {
const updatedBody = _.mergeWith(jsonBody, updateJsonBody, (_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores

@@ -332,2 +335,11 @@ // undefined return values here. Fortunately, JSON.stringify

}
else if (patchJsonBody) {
const { body: realBody } = await (0, request_utils_1.waitForCompletedRequest)(clientReq);
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't patch JSON in non-JSON request body");
}
(0, fast_json_patch_1.applyPatch)(jsonBody, patchJsonBody, true); // Mutates the JSON body returned above
reqBodyOverride = (0, buffer_utils_1.asBuffer)(JSON.stringify(jsonBody));
}
else if (matchReplaceBody) {

@@ -412,3 +424,3 @@ const { body: realBody } = await (0, request_utils_1.waitForCompletedRequest)(clientReq);

if (modifiedReq?.url) {
if (!(0, request_utils_1.isAbsoluteUrl)(modifiedReq?.url))
if (!(0, url_1.isAbsoluteUrl)(modifiedReq?.url))
throw new Error("Overridden request URLs must be absolute");

@@ -419,3 +431,3 @@ ({ protocol, hostname, port, path } = url.parse(reqUrl));

}
const effectivePort = (0, request_utils_1.getEffectivePort)({ protocol, port });
const effectivePort = (0, url_1.getEffectivePort)({ protocol, port });
const strictHttpsChecks = (0, passthrough_handling_1.shouldUseStrictHttps)(hostname, effectivePort, this.ignoreHostHttpsErrors);

@@ -557,3 +569,3 @@ // Use a client cert if it's listed for the host+port or whole hostname

let serverHeaders = (0, header_utils_1.rawHeadersToObject)(serverRawHeaders);
const { replaceStatus, updateHeaders, replaceHeaders, replaceBody, replaceBodyFromFile, updateJsonBody, matchReplaceBody } = this.transformResponse;
const { replaceStatus, updateHeaders, replaceHeaders, replaceBody, replaceBodyFromFile, updateJsonBody, patchJsonBody, matchReplaceBody } = this.transformResponse;
if (replaceStatus) {

@@ -583,6 +595,7 @@ serverStatusCode = replaceStatus;

const realBody = (0, request_utils_1.buildBodyReader)(originalBody, serverRes.headers);
if (await realBody.getJson() === undefined) {
throw new Error("Can't transform non-JSON response body");
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't update JSON in non-JSON response body");
}
const updatedBody = _.mergeWith(await realBody.getJson(), updateJsonBody, (_oldValue, newValue) => {
const updatedBody = _.mergeWith(jsonBody, updateJsonBody, (_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores

@@ -596,2 +609,12 @@ // undefined return values here. Fortunately, JSON.stringify

}
else if (patchJsonBody) {
originalBody = await (0, buffer_utils_1.streamToBuffer)(serverRes);
const realBody = (0, request_utils_1.buildBodyReader)(originalBody, serverRes.headers);
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't patch JSON in non-JSON response body");
}
(0, fast_json_patch_1.applyPatch)(jsonBody, patchJsonBody, true); // Mutates the JSON body returned above
resBodyOverride = (0, buffer_utils_1.asBuffer)(JSON.stringify(jsonBody));
}
else if (matchReplaceBody) {

@@ -598,0 +621,0 @@ originalBody = await (0, buffer_utils_1.streamToBuffer)(serverRes);

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

Object.defineProperty(exports, "TimeoutHandler", { enumerable: true, get: function () { return request_handlers_1.TimeoutHandler; } });
const url_1 = require("../../util/url");
const request_utils_1 = require("../../util/request-utils");

@@ -208,3 +209,3 @@ const header_utils_1 = require("../../util/header-utils");

const parsedUrl = url.parse(wsUrl);
const effectivePort = (0, request_utils_1.getEffectivePort)(parsedUrl);
const effectivePort = (0, url_1.getEffectivePort)(parsedUrl);
const strictHttpsChecks = (0, passthrough_handling_1.shouldUseStrictHttps)(parsedUrl.hostname, effectivePort, this.ignoreHostHttpsErrors);

@@ -211,0 +212,0 @@ // Use a client cert if it's listed for the host+port or whole hostname

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

const util_1 = require("../util/util");
const url_1 = require("../util/url");
const socket_util_1 = require("../util/socket-util");

@@ -409,3 +410,3 @@ const request_utils_1 = require("../util/request-utils");

// It might not be if this is a direct request, or if it's being transparently proxied.
if (!(0, request_utils_1.isAbsoluteUrl)(req.url)) {
if (!(0, url_1.isAbsoluteUrl)(req.url)) {
req.protocol = req.headers[':scheme'] ||

@@ -430,3 +431,3 @@ (req.socket.__lastHopEncrypted ? 'https' : 'http');

req.protocol = req.url.split('://', 1)[0];
req.path = (0, request_utils_1.getPathFromAbsoluteUrl)(req.url);
req.path = (0, url_1.getPathFromAbsoluteUrl)(req.url);
}

@@ -433,0 +434,0 @@ if (type === 'websocket') {

@@ -8,11 +8,2 @@ /// <reference types="node" />

import { Headers, OngoingRequest, CompletedRequest, OngoingResponse, CompletedResponse, CompletedBody, TimingEvents, InitiatedRequest, RawHeaders } from "../types";
export declare const isAbsoluteUrl: (url: string) => boolean;
export declare const isRelativeUrl: (url: string) => boolean;
export declare const isAbsoluteProtocollessUrl: (url: string) => boolean;
export declare const getUrlWithoutProtocol: (url: string) => string;
export declare const getPathFromAbsoluteUrl: (url: string) => string;
export declare const getEffectivePort: (url: {
protocol: string | null;
port: string | null;
}) => number;
export declare const shouldKeepAlive: (req: OngoingRequest) => boolean;

@@ -19,0 +10,0 @@ export declare const writeHead: (response: http.ServerResponse | http2.Http2ServerResponse, status: number, statusMessage?: string | undefined, headers?: Headers | RawHeaders | undefined) => void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseRawHttpResponse = exports.tryToParseHttpRequest = exports.waitForCompletedResponse = exports.trackResponse = exports.waitForCompletedRequest = exports.buildInitiatedRequest = exports.parseRequestBody = exports.buildBodyReader = exports.isMockttpBody = exports.decodeBodyBuffer = exports.encodeBodyBuffer = exports.isHttp2 = exports.writeHead = exports.shouldKeepAlive = exports.getEffectivePort = exports.getPathFromAbsoluteUrl = exports.getUrlWithoutProtocol = exports.isAbsoluteProtocollessUrl = exports.isRelativeUrl = exports.isAbsoluteUrl = void 0;
exports.parseRawHttpResponse = exports.tryToParseHttpRequest = exports.waitForCompletedResponse = exports.trackResponse = exports.waitForCompletedRequest = exports.buildInitiatedRequest = exports.parseRequestBody = exports.buildBodyReader = exports.isMockttpBody = exports.decodeBodyBuffer = exports.encodeBodyBuffer = exports.isHttp2 = exports.writeHead = exports.shouldKeepAlive = void 0;
const _ = require("lodash");

@@ -12,40 +12,4 @@ const tls_1 = require("tls");

const url = require("url");
const util_1 = require("./util");
const buffer_utils_1 = require("./buffer-utils");
const header_utils_1 = require("./header-utils");
// Is this URL fully qualified?
// Note that this supports only HTTP - no websockets or anything else.
const isAbsoluteUrl = (url) => url.toLowerCase().startsWith('http://') ||
url.toLowerCase().startsWith('https://');
exports.isAbsoluteUrl = isAbsoluteUrl;
const isRelativeUrl = (url) => url.startsWith('/');
exports.isRelativeUrl = isRelativeUrl;
const isAbsoluteProtocollessUrl = (url) => !(0, exports.isAbsoluteUrl)(url) && !(0, exports.isRelativeUrl)(url);
exports.isAbsoluteProtocollessUrl = isAbsoluteProtocollessUrl;
const getUrlWithoutProtocol = (url) => {
return url.split('://', 2).slice(-1).join('');
};
exports.getUrlWithoutProtocol = getUrlWithoutProtocol;
const getPathFromAbsoluteUrl = (url) => {
const pathIndex = (0, util_1.nthIndexOf)(url, '/', 3);
if (pathIndex !== -1) {
return url.slice(pathIndex);
}
else {
return '';
}
};
exports.getPathFromAbsoluteUrl = getPathFromAbsoluteUrl;
const getEffectivePort = (url) => {
if (url.port) {
return parseInt(url.port, 10);
}
else if (url.protocol === 'https:' || url.protocol === 'wss:') {
return 443;
}
else {
return 80;
}
};
exports.getEffectivePort = getEffectivePort;
const shouldKeepAlive = (req) => req.httpVersion !== '1.0' &&

@@ -52,0 +16,0 @@ req.headers['connection'] !== 'close' &&

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

@@ -180,2 +180,3 @@ "exports": {

"express": "^4.14.0",
"fast-json-patch": "^3.1.1",
"graphql": "^14.0.2 || ^15.5",

@@ -182,0 +183,0 @@ "graphql-http": "^1.22.0",

@@ -12,8 +12,8 @@ import * as _ from 'lodash';

getUrlWithoutProtocol,
waitForCompletedRequest
} from '../util/request-utils';
normalizeUrl
} from '../util/url';
import { waitForCompletedRequest } from '../util/request-utils';
import { Serializable, ClientServerChannel } from "../serialization/serialization";
import { withDeserializedBodyReader, withSerializedBodyReader } from '../serialization/body-serialization';
import { MaybePromise, Replace } from '../util/type-utils';
import { normalizeUrl } from '../util/normalize-url';

@@ -20,0 +20,0 @@ export interface RequestMatcher extends Explainable, Serializable {

@@ -7,2 +7,6 @@ import _ = require('lodash');

import { stripIndent } from 'common-tags';
import {
Operation as JsonPatchOperation,
validate as validateJsonPatch
} from 'fast-json-patch';

@@ -601,4 +605,7 @@ import {

* A JSON object which will be merged with the real request body. Undefined values
* will be removed. Any requests which are received with an invalid JSON body that
* match this rule will fail.
* will be removed, and other values will be merged directly with the target value
* recursively.
*
* Any requests which are received with an invalid JSON body that match this rule
* will fail.
*/

@@ -610,2 +617,11 @@ updateJsonBody?: {

/**
* A series of operations to apply to the request body in JSON Patch format (RFC
* 6902).
*
* Any requests which are received with an invalid JSON body that match this rule
* will fail.
*/
patchJsonBody?: Array<JsonPatchOperation>;
/**
* Perform a series of string match & replace operations on the request body.

@@ -662,4 +678,7 @@ *

* A JSON object which will be merged with the real response body. Undefined values
* will be removed. Any responses which are received with an invalid JSON body that
* match this rule will fail.
* will be removed, and other values will be merged directly with the target value
* recursively.
*
* Any responses which are received with an invalid JSON body that match this rule
* will fail.
*/

@@ -671,2 +690,11 @@ updateJsonBody?: {

/**
* A series of operations to apply to the response body in JSON Patch format (RFC
* 6902).
*
* Any responses which are received with an invalid JSON body that match this rule
* will fail.
*/
patchJsonBody?: Array<JsonPatchOperation>;
/**
* Perform a series of string match & replace operations on the response body.

@@ -818,2 +846,3 @@ *

options.transformRequest.updateJsonBody,
options.transformRequest.patchJsonBody,
options.transformRequest.matchReplaceBody

@@ -824,2 +853,7 @@ ].filter(o => !!o).length > 1) {

if (options.transformRequest.patchJsonBody) {
const validationError = validateJsonPatch(options.transformRequest.patchJsonBody);
if (validationError) throw validationError;
}
this.transformRequest = options.transformRequest;

@@ -843,2 +877,3 @@ }

options.transformResponse.updateJsonBody,
options.transformResponse.patchJsonBody,
options.transformResponse.matchReplaceBody

@@ -849,2 +884,7 @@ ].filter(o => !!o).length > 1) {

if (options.transformResponse.patchJsonBody) {
const validationError = validateJsonPatch(options.transformResponse.patchJsonBody);
if (validationError) throw validationError;
}
this.transformResponse = options.transformResponse;

@@ -851,0 +891,0 @@ }

@@ -14,2 +14,3 @@ import _ = require('lodash');

import { TypedError } from 'typed-error';
import { applyPatch as applyJsonPatch } from 'fast-json-patch';

@@ -24,2 +25,3 @@ import {

import { MaybePromise } from '../../util/type-utils';
import { isAbsoluteUrl, getEffectivePort } from '../../util/url';
import {

@@ -30,6 +32,4 @@ waitForCompletedRequest,

isHttp2,
isAbsoluteUrl,
writeHead,
encodeBodyBuffer,
getEffectivePort
encodeBodyBuffer
} from '../../util/request-utils';

@@ -499,2 +499,3 @@ import {

updateJsonBody,
patchJsonBody,
matchReplaceBody

@@ -526,18 +527,24 @@ } = this.transformRequest;

const { body: realBody } = await waitForCompletedRequest(clientReq);
if (await realBody.getJson() === undefined) {
throw new Error("Can't transform non-JSON request body");
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't update JSON in non-JSON request body");
}
const updatedBody = _.mergeWith(
await realBody.getJson(),
updateJsonBody,
(_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores
// undefined return values here. Fortunately, JSON.stringify
// ignores Symbols, omitting them from the result.
if (newValue === undefined) return OMIT_SYMBOL;
}
);
const updatedBody = _.mergeWith(jsonBody, updateJsonBody, (_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores
// undefined return values here. Fortunately, JSON.stringify
// ignores Symbols, omitting them from the result.
if (newValue === undefined) return OMIT_SYMBOL;
});
reqBodyOverride = asBuffer(JSON.stringify(updatedBody));
} else if (patchJsonBody) {
const { body: realBody } = await waitForCompletedRequest(clientReq);
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't patch JSON in non-JSON request body");
}
applyJsonPatch(jsonBody, patchJsonBody, true); // Mutates the JSON body returned above
reqBodyOverride = asBuffer(JSON.stringify(jsonBody));
} else if (matchReplaceBody) {

@@ -837,2 +844,3 @@ const { body: realBody } = await waitForCompletedRequest(clientReq);

updateJsonBody,
patchJsonBody,
matchReplaceBody

@@ -864,19 +872,27 @@ } = this.transformResponse;

const realBody = buildBodyReader(originalBody, serverRes.headers);
const jsonBody = await realBody.getJson();
if (await realBody.getJson() === undefined) {
throw new Error("Can't transform non-JSON response body");
if (jsonBody === undefined) {
throw new Error("Can't update JSON in non-JSON response body");
}
const updatedBody = _.mergeWith(
await realBody.getJson(),
updateJsonBody,
(_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores
// undefined return values here. Fortunately, JSON.stringify
// ignores Symbols, omitting them from the result.
if (newValue === undefined) return OMIT_SYMBOL;
}
);
const updatedBody = _.mergeWith(jsonBody, updateJsonBody, (_oldValue, newValue) => {
// We want to remove values with undefines, but Lodash ignores
// undefined return values here. Fortunately, JSON.stringify
// ignores Symbols, omitting them from the result.
if (newValue === undefined) return OMIT_SYMBOL;
});
resBodyOverride = asBuffer(JSON.stringify(updatedBody));
} else if (patchJsonBody) {
originalBody = await streamToBuffer(serverRes);
const realBody = buildBodyReader(originalBody, serverRes.headers);
const jsonBody = await realBody.getJson();
if (jsonBody === undefined) {
throw new Error("Can't patch JSON in non-JSON response body");
}
applyJsonPatch(jsonBody, patchJsonBody, true); // Mutates the JSON body returned above
resBodyOverride = asBuffer(JSON.stringify(jsonBody));
} else if (matchReplaceBody) {

@@ -883,0 +899,0 @@ originalBody = await streamToBuffer(serverRes);

@@ -22,7 +22,5 @@ import * as _ from 'lodash';

} from '../requests/request-handlers';
import { getEffectivePort } from '../../util/url';
import { isHttp2 } from '../../util/request-utils';
import {
getEffectivePort,
isHttp2
} from '../../util/request-utils';
import {
findRawHeader,

@@ -29,0 +27,0 @@ findRawHeaders,

@@ -48,2 +48,3 @@ import _ = require("lodash");

import { isAbsoluteUrl, getPathFromAbsoluteUrl } from "../util/url";
import { buildSocketEventData, isSocketLoop, resetOrDestroy } from "../util/socket-util";

@@ -55,7 +56,5 @@ import {

waitForCompletedResponse,
isAbsoluteUrl,
buildInitiatedRequest,
tryToParseHttpRequest,
buildBodyReader,
getPathFromAbsoluteUrl,
parseRawHttpResponse

@@ -62,0 +61,0 @@ } from "../util/request-utils";

@@ -26,3 +26,2 @@ import * as _ from 'lodash';

import { nthIndexOf } from './util';
import {

@@ -44,37 +43,2 @@ bufferThenStream,

// Is this URL fully qualified?
// Note that this supports only HTTP - no websockets or anything else.
export const isAbsoluteUrl = (url: string) =>
url.toLowerCase().startsWith('http://') ||
url.toLowerCase().startsWith('https://');
export const isRelativeUrl = (url: string) =>
url.startsWith('/');
export const isAbsoluteProtocollessUrl = (url: string) =>
!isAbsoluteUrl(url) && !isRelativeUrl(url);
export const getUrlWithoutProtocol = (url: string): string => {
return url.split('://', 2).slice(-1).join('');
}
export const getPathFromAbsoluteUrl = (url: string) => {
const pathIndex = nthIndexOf(url, '/', 3);
if (pathIndex !== -1) {
return url.slice(pathIndex);
} else {
return '';
}
}
export const getEffectivePort = (url: { protocol: string | null, port: string | null }) => {
if (url.port) {
return parseInt(url.port, 10);
} else if (url.protocol === 'https:' || url.protocol === 'wss:') {
return 443;
} else {
return 80;
}
}
export const shouldKeepAlive = (req: OngoingRequest): boolean =>

@@ -81,0 +45,0 @@ req.httpVersion !== '1.0' &&

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

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

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