Skip to content

Commit 0d81c81

Browse files
committed
feat(MongoBinaryDownload): add option to configure max amount of redirects
1 parent 9ec4aee commit 0d81c81

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

docs/api/config-options.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ Option `USE_HTTP` is used to use `http` over `https`
191191

192192
Default: `false`
193193

194+
### MAX_REDIRECTS
195+
196+
| Environment Variable | PackageJson |
197+
| :------------------: | :---------: |
198+
| `MONGOMS_MAX_REDIRECTS` | `maxRedirects` |
199+
200+
Option `MAX_REDIRECTS` is used to set the maximal amount of redirects to follow
201+
202+
Default: `2`
203+
194204
### USE_ARCHIVE_NAME_FOR_BINARY_NAME
195205

196206
| Environment Variable | PackageJson |

packages/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,16 @@ export class MongoBinaryDownload {
410410
log('httpDownload');
411411
const downloadUrl = this.assignDownloadingURL(url);
412412

413+
const maxRedirects = parseInt(resolveConfig(ResolveConfigVariables.MAX_REDIRECTS) || '');
414+
const useHttpsOptions: Parameters<typeof https.get>[1] = {
415+
maxRedirects: Number.isNaN(maxRedirects) ? 2 : maxRedirects,
416+
...httpOptions,
417+
};
418+
413419
return new Promise((resolve, reject) => {
414420
log(`httpDownload: trying to download "${downloadUrl}"`);
415421
https
416-
.get(url, httpOptions, (response) => {
422+
.get(url, useHttpsOptions, (response) => {
417423
if (response.statusCode != 200) {
418424
if (response.statusCode === 403) {
419425
reject(

packages/mongodb-memory-server-core/src/util/resolveConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export enum ResolveConfigVariables {
2525
USE_HTTP = 'USE_HTTP',
2626
SYSTEM_BINARY_VERSION_CHECK = 'SYSTEM_BINARY_VERSION_CHECK',
2727
USE_ARCHIVE_NAME_FOR_BINARY_NAME = 'USE_ARCHIVE_NAME_FOR_BINARY_NAME',
28+
MAX_REDIRECTS = 'MAX_REDIRECTS',
2829
}
2930

3031
/** The Prefix for Environmental values */
@@ -40,6 +41,7 @@ export const defaultValues = new Map<ResolveConfigVariables, string>([
4041
[ResolveConfigVariables.USE_HTTP, 'false'],
4142
[ResolveConfigVariables.SYSTEM_BINARY_VERSION_CHECK, 'true'],
4243
[ResolveConfigVariables.USE_ARCHIVE_NAME_FOR_BINARY_NAME, 'false'],
44+
[ResolveConfigVariables.MAX_REDIRECTS, '2'],
4345
]);
4446

4547
/** Interface for storing information about the found package.json from `findPackageJson` */

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,13 @@
20122012
resolved "https://registry.yarnpkg.com/@types/find-cache-dir/-/find-cache-dir-3.2.1.tgz#7b959a4b9643a1e6a1a5fe49032693cc36773501"
20132013
integrity sha512-frsJrz2t/CeGifcu/6uRo4b+SzAwT4NYCVPu1GN8IB9XTzrpPkGuV0tmh9mN+/L0PklAlsC3u5Fxt0ju00LXIw==
20142014

2015+
"@types/follow-redirects@^1.14.1":
2016+
version "1.14.1"
2017+
resolved "https://registry.yarnpkg.com/@types/follow-redirects/-/follow-redirects-1.14.1.tgz#c08b173be7517ddc53725d0faf9648d4dc7a9cdb"
2018+
integrity sha512-THBEFwqsLuU/K62B5JRwab9NW97cFmL4Iy34NTMX0bMycQVzq2q7PKOkhfivIwxdpa/J72RppgC42vCHfwKJ0Q==
2019+
dependencies:
2020+
"@types/node" "*"
2021+
20152022
"@types/graceful-fs@^4.1.3":
20162023
version "4.1.5"
20172024
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
@@ -3784,6 +3791,11 @@ flatted@^3.1.0:
37843791
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
37853792
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
37863793

3794+
follow-redirects@^1.15.2:
3795+
version "1.15.2"
3796+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
3797+
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
3798+
37873799
forever-agent@~0.6.1:
37883800
version "0.6.1"
37893801
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"

0 commit comments

Comments
 (0)