Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('`.maxHeadersCount` - getter', wrapper, async (t, server) => {
const request = makeRequest(server.options);
t.is(request.maxHeadersCount, undefined);
request.end();
await pEvent(request, 'response');
request.abort();
t.true(is.number(request.maxHeadersCount));
});
const response = await pEvent(request, 'response');
response.resume();
t.true(is.plainObject(response.headers));
t.true(is.array(response.rawHeaders));
t.true(is.plainObject(response.trailers));
t.true(is.array(response.rawTrailers));
t.is(request.socket, request.connection);
t.is(response.socket, request.socket);
t.is(response.connection, request.socket);
t.truthy(response.req);
t.is(response.httpVersion, '2.0');
t.is(response.httpVersionMajor, 2);
t.is(response.httpVersionMinor, 0);
t.true(is.number(response.statusCode));
t.is(response.statusMessage, '');
});
const checkEvents: Macro<[Progress[], number?]> = (t, events, bodySize = undefined) => {
t.true(events.length >= 2);
let lastEvent = events.shift()!;
if (!is.number(bodySize)) {
t.is(lastEvent.percent, 0);
}
for (const [index, event] of events.entries()) {
if (is.number(bodySize)) {
t.is(event.percent, event.transferred / bodySize);
t.true(event.percent > lastEvent.percent);
} else {
const isLastEvent = index === events.length - 1;
t.is(event.percent, isLastEvent ? 1 : 0);
}
t.true(event.transferred >= lastEvent.transferred);
t.is(event.total, bodySize);
lastEvent = event;
}
};
calculateDelay: ({attemptCount}) => {
t.true(is.number(attemptCount));
return attemptCount < 2 ? 1 : 0;
}
}
if (iter > retries || !isRetryAllowed(err)) {
return 0;
}
const noise = Math.random() * 100;
return ((1 << iter) * 1000) + noise;
};
}
if (is.undefined(opts.followRedirect)) {
opts.followRedirect = true;
}
if (opts.timeout) {
if (is.number(opts.timeout)) {
opts.gotTimeout = {request: opts.timeout};
} else {
opts.gotTimeout = opts.timeout;
}
delete opts.timeout;
}
return opts;
}
options.hooks = {};
} else if (!is.object(options.hooks)) {
throw new TypeError(`Parameter \`hooks\` must be an object, not ${is(options.hooks)}`);
}
for (const event of knownHookEvents) {
if (is.nullOrUndefined(options.hooks[event])) {
if (defaults) {
options.hooks[event] = [...defaults.hooks[event]];
} else {
options.hooks[event] = [];
}
}
}
if (is.number(options.timeout)) {
options.gotTimeout = {request: options.timeout};
} else if (is.object(options.timeout)) {
options.gotTimeout = options.timeout;
}
delete options.timeout;
const {retry} = options;
options.retry = {
retries: 0,
methods: [],
statusCodes: [],
errorCodes: []
};
if (is.nonEmptyObject(defaults) && retry !== false) {
? this.renderObject({ objectURL, contentType, i18n, isViewOnce })
: null}
{caption ? <div style="{styles.caption}">{caption}</div> : null}
<div style="{styles.controls}">
{onSave ? (
) : null}
</div>
{isViewOnce && is.number(videoTime) ? (
<div style="{styles.navigationContainer}">
<div style="{styles.timestampPill}">{formatDuration(videoTime)}</div>
</div>
) : (
<div style="{styles.navigationContainer}">
{onPrevious ? (
) : (
)}
{onNext ? (
) : (
)}
</div>
delete options.timeout;
const {retry} = options;
options.retry = {
retries: 0,
methods: [],
statusCodes: [],
errorCodes: []
};
if (is.nonEmptyObject(defaults) && retry !== false) {
options.retry = {...defaults.retry};
}
if (retry !== false) {
if (is.number(retry)) {
options.retry.retries = retry;
} else {
options.retry = {...options.retry, ...retry};
}
}
if (options.gotTimeout) {
options.retry.maxRetryAfter = Math.min(...[options.gotTimeout.request, options.gotTimeout.connection].filter(n => !is.nullOrUndefined(n)));
}
if (is.array(options.retry.methods)) {
options.retry.methods = new Set(options.retry.methods.map(method => method.toUpperCase()));
}
if (is.array(options.retry.statusCodes)) {
options.retry.statusCodes = new Set(options.retry.statusCodes);
if (iter > retries || !isRetryAllowed(err)) {
return 0;
}
const noise = Math.random() * 100;
return ((1 << iter) * 1000) + noise;
};
}
if (is.undefined(opts.followRedirect)) {
opts.followRedirect = true;
}
if (opts.timeout) {
if (is.number(opts.timeout)) {
opts.gotTimeout = {request: opts.timeout};
} else {
opts.gotTimeout = opts.timeout;
}
delete opts.timeout;
}
return opts;
}