175 lines
28 KiB
JavaScript
175 lines
28 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createRequestOptions = void 0;
|
|
const lodash_1 = require("lodash");
|
|
const is_stream_1 = __importDefault(require("is-stream"));
|
|
const interfaces_1 = require("./interfaces");
|
|
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
|
|
const content_types_1 = __importDefault(require("../../assets/content-types"));
|
|
const http_headers_1 = __importDefault(require("../../utils/http-headers"));
|
|
const types_1 = require("../../errors/types");
|
|
const runtime_1 = require("../../errors/runtime");
|
|
const actions_1 = require("../commands/actions");
|
|
const DEFAULT_ACCEPT = { [http_headers_1.default.accept]: `${content_types_1.default.json}, ${content_types_1.default.textPlain}, ${content_types_1.default.all}` };
|
|
const METHODS_WITH_CONTENT_TYPE = ['post', 'put', 'patch'];
|
|
const DEFAULT_REQUEST_METHOD = 'GET';
|
|
const DEFAULT_PROTOCOL = 'http:';
|
|
function setContentTypeIfNotExists(headers, value) {
|
|
if (!(0, lodash_1.isUndefined)(headers) && (0, lodash_1.isUndefined)(headers[http_headers_1.default.contentType]))
|
|
headers[http_headers_1.default.contentType] = value;
|
|
}
|
|
function typeOf(value) {
|
|
if (value === null)
|
|
return 'null';
|
|
if (value && typeof value === 'object')
|
|
return value.constructor.name.toLowerCase();
|
|
return typeof value;
|
|
}
|
|
function transformBody(headers, body) {
|
|
if (!body)
|
|
return Buffer.from('');
|
|
if (typeOf(body) === 'formdata' ||
|
|
typeOf(body) === 'file' ||
|
|
typeOf(body) === 'blob' ||
|
|
(0, lodash_1.isArrayBuffer)(body) ||
|
|
(0, lodash_1.isBuffer)(body) ||
|
|
(0, is_stream_1.default)(body))
|
|
return Buffer.from(body);
|
|
else if (ArrayBuffer.isView(body))
|
|
return Buffer.from(body.buffer);
|
|
else if (body instanceof URLSearchParams) {
|
|
setContentTypeIfNotExists(headers, `${content_types_1.default.urlencoded};charset=utf-8`);
|
|
return Buffer.from(body.toString());
|
|
}
|
|
else if ((0, lodash_1.isObject)(body) || headers && headers[http_headers_1.default.contentType] === content_types_1.default.json) {
|
|
setContentTypeIfNotExists(headers, content_types_1.default.json);
|
|
return Buffer.from(JSON.stringify(body));
|
|
}
|
|
else if (typeof body === 'string')
|
|
setContentTypeIfNotExists(headers, content_types_1.default.textPlain);
|
|
return body;
|
|
}
|
|
function getAuthString(auth) {
|
|
return 'Basic ' + Buffer.from(auth.username + ':' + auth.password, 'utf8').toString('base64');
|
|
}
|
|
function changeHeaderNamesToLowercase(headers) {
|
|
const lowerCaseHeaders = {};
|
|
Object.keys(headers).forEach(headerName => {
|
|
lowerCaseHeaders[headerName.toLowerCase()] = headers[headerName];
|
|
});
|
|
return lowerCaseHeaders;
|
|
}
|
|
async function prepareHeaders(headers, currentPageUrl, url, body, testRun, withCredentials, options) {
|
|
var _a;
|
|
const { host, origin } = url;
|
|
const preparedHeaders = Object.assign({}, DEFAULT_ACCEPT, changeHeaderNamesToLowercase(headers));
|
|
preparedHeaders[http_headers_1.default.host] = host;
|
|
preparedHeaders[http_headers_1.default.origin] = origin;
|
|
preparedHeaders[http_headers_1.default.contentLength] = body.length;
|
|
if (headers.method && METHODS_WITH_CONTENT_TYPE.includes(String(headers.method)))
|
|
preparedHeaders[http_headers_1.default.contentType] = content_types_1.default.urlencoded;
|
|
if (options.auth && withCredentials)
|
|
preparedHeaders[http_headers_1.default.authorization] = getAuthString(options.auth);
|
|
if ((_a = options.proxy) === null || _a === void 0 ? void 0 : _a.auth)
|
|
preparedHeaders[http_headers_1.default.proxyAuthorization] = getAuthString(options.proxy.auth);
|
|
if (withCredentials) {
|
|
const currentPageCookies = testRun.session.cookies.getHeader({
|
|
url: currentPageUrl.href,
|
|
hostname: currentPageUrl.hostname,
|
|
});
|
|
if (currentPageCookies)
|
|
preparedHeaders[http_headers_1.default.cookie] = currentPageCookies;
|
|
}
|
|
//NOTE: Additional header to recognize API requests in the hammerhead
|
|
preparedHeaders[http_headers_1.default.isApiRequest] = 'true';
|
|
return preparedHeaders;
|
|
}
|
|
async function prepareUrl(testRun, currentPageUrl, url, callsite) {
|
|
let preparedUrl;
|
|
try {
|
|
preparedUrl = url instanceof URL
|
|
? url
|
|
: new URL(url, currentPageUrl.hostname ? currentPageUrl.origin : void 0);
|
|
}
|
|
catch (e) {
|
|
throw new runtime_1.APIError(callsite, types_1.RUNTIME_ERRORS.requestUrlInvalidValueError, url);
|
|
}
|
|
return preparedUrl;
|
|
}
|
|
function prepareSearchParams(url, params) {
|
|
if (!params)
|
|
return url;
|
|
let searchParams;
|
|
if (params instanceof URLSearchParams)
|
|
searchParams = params;
|
|
else {
|
|
searchParams = new URLSearchParams();
|
|
for (const key in params) {
|
|
if (!params[key])
|
|
continue;
|
|
(0, lodash_1.castArray)(params[key]).forEach(v => {
|
|
searchParams.append(key, typeof v === 'object' ? JSON.stringify(v) : String(v));
|
|
});
|
|
}
|
|
}
|
|
return `${url}${url.includes('?') ? '&' : '?'}${searchParams.toString()}`;
|
|
}
|
|
function getProxyUrl(testRun, url, withCredentials) {
|
|
return testRun.executeCommand(new actions_1.GetProxyUrlCommand({
|
|
url: url,
|
|
options: { credentials: withCredentials ? interfaces_1.Credentials.include : interfaces_1.Credentials.omit },
|
|
}, testRun, true));
|
|
}
|
|
async function createRequestOptions(currentPageUrl, testRun, options, callsite) {
|
|
options.headers = options.headers || {};
|
|
const url = await prepareUrl(testRun, currentPageUrl, options.url, callsite);
|
|
const withCredentials = !currentPageUrl.host || (0, testcafe_hammerhead_1.sameOriginCheck)(currentPageUrl.href, url.href) || options.withCredentials || false;
|
|
const body = transformBody(options.headers, options.body);
|
|
const headers = await prepareHeaders(options.headers, currentPageUrl, url, body, testRun, withCredentials, options);
|
|
const proxyUrl = await getProxyUrl(testRun, url.href, withCredentials);
|
|
const proxyUrlObj = (0, testcafe_hammerhead_1.parseProxyUrl)(proxyUrl);
|
|
let auth = options.auth;
|
|
if (!auth && url.username && url.password) {
|
|
auth = {
|
|
username: url.username,
|
|
password: url.password,
|
|
};
|
|
}
|
|
const requestParams = {
|
|
method: options.method || DEFAULT_REQUEST_METHOD,
|
|
url: proxyUrl,
|
|
protocol: DEFAULT_PROTOCOL,
|
|
hostname: proxyUrlObj.proxy.hostname,
|
|
host: proxyUrlObj.proxy.hostname,
|
|
port: proxyUrlObj.proxy.port,
|
|
path: prepareSearchParams(proxyUrlObj.partAfterHost, options.params),
|
|
auth: auth && withCredentials ? `${auth.username}:${auth.password}` : void 0,
|
|
headers: headers,
|
|
credentials: withCredentials ? testRun.session.getAuthCredentials() : void 0,
|
|
body: body,
|
|
disableHttp2: testRun.session.isHttp2Disabled(),
|
|
requestTimeout: {
|
|
ajax: options.timeout,
|
|
page: options.timeout,
|
|
},
|
|
};
|
|
if (options.proxy) {
|
|
requestParams.externalProxySettings = {
|
|
host: options.proxy.host,
|
|
hostname: options.proxy.host,
|
|
port: options.proxy.port.toString(),
|
|
proxyAuth: options.proxy.auth ? `${options.proxy.auth.username}:${options.proxy.auth.password}` : void 0,
|
|
};
|
|
requestParams.protocol = url.protocol;
|
|
requestParams.host = url.host;
|
|
requestParams.hostname = url.hostname;
|
|
requestParams.port = url.port;
|
|
requestParams.path = prepareSearchParams(url.pathname + url.search, options.params);
|
|
}
|
|
return new testcafe_hammerhead_1.RequestOptions(requestParams);
|
|
}
|
|
exports.createRequestOptions = createRequestOptions;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLXJlcXVlc3Qtb3B0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90ZXN0LXJ1bi9yZXF1ZXN0L2NyZWF0ZS1yZXF1ZXN0LW9wdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQ0EsbUNBTWdCO0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XQgZ2V0UHJveHlVcmwodGVzdFJ1biwgdXJsLmhyZWYsIHdpdGhDcmVkZW50aWFscyk7XG4gICAgY29uc3QgcHJveHlVcmxPYmogICAgID0gcGFyc2VQcm94eVVybChwcm94eVVybCk7XG4gICAgbGV0IGF1dGggICAgICAgICAgICAgID0gb3B0aW9ucy5hdXRoO1xuXG4gICAgaWYgKCFhdXRoICYmIHVybC51c2VybmFtZSAmJiB1cmwucGFzc3dvcmQpIHtcbiAgICAgICAgYXV0aCA9IHtcbiAgICAgICAgICAgIHVzZXJuYW1lOiB1cmwudXNlcm5hbWUsXG4gICAgICAgICAgICBwYXNzd29yZDogdXJsLnBhc3N3b3JkLFxuICAgICAgICB9O1xuICAgIH1cblxuICAgIGNvbnN0IHJlcXVlc3RQYXJhbXM6IFJlcXVlc3RPcHRpb25zUGFyYW1zID0ge1xuICAgICAgICBtZXRob2Q6ICAgICAgICAgb3B0aW9ucy5tZXRob2QgfHwgREVGQVVMVF9SRVFVRVNUX01FVEhPRCxcbiAgICAgICAgdXJsOiAgICAgICAgICAgIHByb3h5VXJsLFxuICAgICAgICBwcm90b2NvbDogICAgICAgREVGQVVMVF9QUk9UT0NPTCxcbiAgICAgICAgaG9zdG5hbWU6ICAgICAgIHByb3h5VXJsT2JqLnByb3h5Lmhvc3RuYW1lLFxuICAgICAgICBob3N0OiAgICAgICAgICAgcHJveHlVcmxPYmoucHJveHkuaG9zdG5hbWUsXG4gICAgICAgIHBvcnQ6ICAgICAgICAgICBwcm94eVVybE9iai5wcm94eS5wb3J0LFxuICAgICAgICBwYXRoOiAgICAgICAgICAgcHJlcGFyZVNlYXJjaFBhcmFtcyhwcm94eVVybE9iai5wYXJ0QWZ0ZXJIb3N0LCBvcHRpb25zLnBhcmFtcyksXG4gICAgICAgIGF1dGg6ICAgICAgICAgICBhdXRoICYmIHdpdGhDcmVkZW50aWFscyA/IGAke2F1dGgudXNlcm5hbWV9OiR7YXV0aC5wYXNzd29yZH1gIDogdm9pZCAwLFxuICAgICAgICBoZWFkZXJzOiAgICAgICAgaGVhZGVycyxcbiAgICAgICAgY3JlZGVudGlhbHM6ICAgIHdpdGhDcmVkZW50aWFscyA/IHRlc3RSdW4uc2Vzc2lvbi5nZXRBdXRoQ3JlZGVudGlhbHMoKSA6IHZvaWQgMCxcbiAgICAgICAgYm9keTogICAgICAgICAgIGJvZHksXG4gICAgICAgIGRpc2FibGVIdHRwMjogICB0ZXN0UnVuLnNlc3Npb24uaXNIdHRwMkRpc2FibGVkKCksXG4gICAgICAgIHJlcXVlc3RUaW1lb3V0OiB7XG4gICAgICAgICAgICBhamF4OiBvcHRpb25zLnRpbWVvdXQsXG4gICAgICAgICAgICBwYWdlOiBvcHRpb25zLnRpbWVvdXQsXG4gICAgICAgIH0sXG4gICAgfTtcblxuICAgIGlmIChvcHRpb25zLnByb3h5KSB7XG4gICAgICAgIHJlcXVlc3RQYXJhbXMuZXh0ZXJuYWxQcm94eVNldHRpbmdzID0ge1xuICAgICAgICAgICAgaG9zdDogICAgICBvcHRpb25zLnByb3h5Lmhvc3QsXG4gICAgICAgICAgICBob3N0bmFtZTogIG9wdGlvbnMucHJveHkuaG9zdCxcbiAgICAgICAgICAgIHBvcnQ6ICAgICAgb3B0aW9ucy5wcm94eS5wb3J0LnRvU3RyaW5nKCksXG4gICAgICAgICAgICBwcm94eUF1dGg6IG9wdGlvbnMucHJveHkuYXV0aCA/IGAke29wdGlvbnMucHJveHkuYXV0aC51c2VybmFtZX06JHtvcHRpb25zLnByb3h5LmF1dGgucGFzc3dvcmR9YCA6IHZvaWQgMCxcbiAgICAgICAgfTtcblxuICAgICAgICByZXF1ZXN0UGFyYW1zLnByb3RvY29sID0gdXJsLnByb3RvY29sO1xuICAgICAgICByZXF1ZXN0UGFyYW1zLmhvc3QgICAgID0gdXJsLmhvc3Q7XG4gICAgICAgIHJlcXVlc3RQYXJhbXMuaG9zdG5hbWUgPSB1cmwuaG9zdG5hbWU7XG4gICAgICAgIHJlcXVlc3RQYXJhbXMucG9ydCAgICAgPSB1cmwucG9ydDtcbiAgICAgICAgcmVxdWVzdFBhcmFtcy5wYXRoICAgICA9IHByZXBhcmVTZWFyY2hQYXJhbXModXJsLnBhdGhuYW1lICsgdXJsLnNlYXJjaCwgb3B0aW9ucy5wYXJhbXMpO1xuICAgIH1cblxuICAgIHJldHVybiBuZXcgUmVxdWVzdE9wdGlvbnMocmVxdWVzdFBhcmFtcyk7XG59XG4iXX0=
|