Skip to content

Commit

Permalink
feat(MongoBinaryDownload): add option to configure max amount of redi…
Browse files Browse the repository at this point in the history
…rects
  • Loading branch information
hasezoey committed Aug 3, 2023
1 parent 9ec4aee commit 0d81c81
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/api/config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ Option `USE_HTTP` is used to use `http` over `https`

Default: `false`

### MAX_REDIRECTS

| Environment Variable | PackageJson |
| :------------------: | :---------: |
| `MONGOMS_MAX_REDIRECTS` | `maxRedirects` |

Option `MAX_REDIRECTS` is used to set the maximal amount of redirects to follow

Default: `2`

### USE_ARCHIVE_NAME_FOR_BINARY_NAME

| Environment Variable | PackageJson |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,16 @@ export class MongoBinaryDownload {
log('httpDownload');
const downloadUrl = this.assignDownloadingURL(url);

const maxRedirects = parseInt(resolveConfig(ResolveConfigVariables.MAX_REDIRECTS) || '');
const useHttpsOptions: Parameters<typeof https.get>[1] = {

Check warning on line 414 in packages/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L414 was not covered by tests
maxRedirects: Number.isNaN(maxRedirects) ? 2 : maxRedirects,
...httpOptions,
};

return new Promise((resolve, reject) => {
log(`httpDownload: trying to download "${downloadUrl}"`);
https
.get(url, httpOptions, (response) => {
.get(url, useHttpsOptions, (response) => {

Check warning on line 422 in packages/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L422 was not covered by tests
if (response.statusCode != 200) {
if (response.statusCode === 403) {
reject(
Expand Down
2 changes: 2 additions & 0 deletions packages/mongodb-memory-server-core/src/util/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum ResolveConfigVariables {
USE_HTTP = 'USE_HTTP',
SYSTEM_BINARY_VERSION_CHECK = 'SYSTEM_BINARY_VERSION_CHECK',
USE_ARCHIVE_NAME_FOR_BINARY_NAME = 'USE_ARCHIVE_NAME_FOR_BINARY_NAME',
MAX_REDIRECTS = 'MAX_REDIRECTS',
}

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

/** Interface for storing information about the found package.json from `findPackageJson` */
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,13 @@
resolved "https://registry.yarnpkg.com/@types/find-cache-dir/-/find-cache-dir-3.2.1.tgz#7b959a4b9643a1e6a1a5fe49032693cc36773501"
integrity sha512-frsJrz2t/CeGifcu/6uRo4b+SzAwT4NYCVPu1GN8IB9XTzrpPkGuV0tmh9mN+/L0PklAlsC3u5Fxt0ju00LXIw==

"@types/follow-redirects@^1.14.1":
version "1.14.1"
resolved "https://registry.yarnpkg.com/@types/follow-redirects/-/follow-redirects-1.14.1.tgz#c08b173be7517ddc53725d0faf9648d4dc7a9cdb"
integrity sha512-THBEFwqsLuU/K62B5JRwab9NW97cFmL4Iy34NTMX0bMycQVzq2q7PKOkhfivIwxdpa/J72RppgC42vCHfwKJ0Q==
dependencies:
"@types/node" "*"

"@types/graceful-fs@^4.1.3":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
Expand Down Expand Up @@ -3784,6 +3791,11 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==

follow-redirects@^1.15.2:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
Expand Down

0 comments on commit 0d81c81

Please sign in to comment.