File tree 3 files changed +40
-2
lines changed
packages/mongodb-memory-server-core/src/util
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,16 @@ Option `DOWNLOAD_URL` is used to overwrite the ***complete*** URL (including [`D
124
124
125
125
Format: ` https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.20.tgz `
126
126
127
+ ### DOWNLOAD_IGNORE_MISSING_HEADER
128
+
129
+ | Environment Variable | PackageJson |
130
+ | :--------------------: | :-----------: |
131
+ | ` DOWNLOAD_IGNORE_MISSING_HEADER ` | ` downloadIgnoreMissingHeader ` |
132
+
133
+ Option ` DOWNLOAD_IGNORE_MISSING_HEADER ` can be set to ` true ` to ignore missing response headers like ` content-length ` .
134
+
135
+ Default: ` false `
136
+
127
137
### PREFER_GLOBAL_PATH
128
138
129
139
| Environment Variable | PackageJson |
Original file line number Diff line number Diff line change @@ -399,14 +399,41 @@ export class MongoBinaryDownload {
399
399
400
400
return ;
401
401
}
402
+
403
+ // content-length, otherwise 0
404
+ let contentLength : number ;
405
+
402
406
if ( typeof response . headers [ 'content-length' ] != 'string' ) {
403
- reject ( new DownloadError ( downloadUrl , 'Response header "content-length" is empty!' ) ) ;
407
+ log ( 'Response header "content-lenght" is empty!' ) ;
408
+
409
+ contentLength = 0 ;
410
+ } else {
411
+ contentLength = parseInt ( response . headers [ 'content-length' ] , 10 ) ;
412
+
413
+ if ( Number . isNaN ( contentLength ) ) {
414
+ log ( 'Response header "content-lenght" resolved to NaN!' ) ;
415
+
416
+ contentLength = 0 ;
417
+ }
418
+ }
419
+
420
+ // error if the content-length header is missing or is 0 if config option "DOWNLOAD_IGNORE_MISSING_HEADER" is not set to "true"
421
+ if (
422
+ ! envToBool ( resolveConfig ( ResolveConfigVariables . DOWNLOAD_IGNORE_MISSING_HEADER ) ) &&
423
+ contentLength <= 0
424
+ ) {
425
+ reject (
426
+ new DownloadError (
427
+ downloadUrl ,
428
+ 'Response header "content-length" does not exist or resolved to NaN'
429
+ )
430
+ ) ;
404
431
405
432
return ;
406
433
}
407
434
408
435
this . dlProgress . current = 0 ;
409
- this . dlProgress . length = parseInt ( response . headers [ 'content-length' ] , 10 ) ;
436
+ this . dlProgress . length = contentLength ;
410
437
this . dlProgress . totalMb = Math . round ( ( this . dlProgress . length / 1048576 ) * 10 ) / 10 ;
411
438
412
439
const fileStream = createWriteStream ( tempDownloadLocation ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export enum ResolveConfigVariables {
16
16
DEBUG = 'DEBUG' ,
17
17
DOWNLOAD_MIRROR = 'DOWNLOAD_MIRROR' ,
18
18
DOWNLOAD_URL = 'DOWNLOAD_URL' ,
19
+ DOWNLOAD_IGNORE_MISSING_HEADER = 'DOWNLOAD_IGNORE_MISSING_HEADER' ,
19
20
PREFER_GLOBAL_PATH = 'PREFER_GLOBAL_PATH' ,
20
21
DISABLE_POSTINSTALL = 'DISABLE_POSTINSTALL' ,
21
22
SYSTEM_BINARY = 'SYSTEM_BINARY' ,
You can’t perform that action at this time.
0 commit comments