File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 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
124124
125125Format: ` https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.20.tgz `
126126
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+
127137### PREFER_GLOBAL_PATH
128138
129139| Environment Variable | PackageJson |
Original file line number Diff line number Diff line change @@ -399,14 +399,41 @@ export class MongoBinaryDownload {
399399
400400 return ;
401401 }
402+
403+ // content-length, otherwise 0
404+ let contentLength : number ;
405+
402406 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+ ) ;
404431
405432 return ;
406433 }
407434
408435 this . dlProgress . current = 0 ;
409- this . dlProgress . length = parseInt ( response . headers [ 'content-length' ] , 10 ) ;
436+ this . dlProgress . length = contentLength ;
410437 this . dlProgress . totalMb = Math . round ( ( this . dlProgress . length / 1048576 ) * 10 ) / 10 ;
411438
412439 const fileStream = createWriteStream ( tempDownloadLocation ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export enum ResolveConfigVariables {
1616 DEBUG = 'DEBUG' ,
1717 DOWNLOAD_MIRROR = 'DOWNLOAD_MIRROR' ,
1818 DOWNLOAD_URL = 'DOWNLOAD_URL' ,
19+ DOWNLOAD_IGNORE_MISSING_HEADER = 'DOWNLOAD_IGNORE_MISSING_HEADER' ,
1920 PREFER_GLOBAL_PATH = 'PREFER_GLOBAL_PATH' ,
2021 DISABLE_POSTINSTALL = 'DISABLE_POSTINSTALL' ,
2122 SYSTEM_BINARY = 'SYSTEM_BINARY' ,
You can’t perform that action at this time.
0 commit comments