add blank headers by default
This commit is contained in:
		
							parent
							
								
									a129fd4e6d
								
							
						
					
					
						commit
						cbbada1b8a
					
				
					 1 changed files with 7 additions and 6 deletions
				
			
		|  | @ -16,18 +16,19 @@ export default class net { | ||||||
| 	@returns {Promise} the downloaded file | 	@returns {Promise} the downloaded file | ||||||
| 	*/ | 	*/ | ||||||
| 	static async download(URL, TYPE, VERIFY_ONLY = false, STRICT = false) { | 	static async download(URL, TYPE, VERIFY_ONLY = false, STRICT = false) { | ||||||
| 		let CONNECT, DATA;  | 		let CONNECT, DATA; | ||||||
| 	 | 		let HEADERS = {};  | ||||||
|  | 		 | ||||||
| 		// If TYPE is used as headers, then the other parts of the header should be taken out for later usage. 
 | 		// If TYPE is used as headers, then the other parts of the header should be taken out for later usage. 
 | ||||||
| 		if (TYPE && (typeof TYPE).includes(`obj`)) { | 		if (TYPE && (typeof TYPE).includes(`obj`)) { | ||||||
| 			let HEADERS = TYPE; | 			HEADERS = TYPE; | ||||||
| 			TYPE = HEADERS[`Content-Type`]; | 			TYPE = HEADERS[`Content-Type`]; | ||||||
| 		} | 		} | ||||||
| 
 | 		 | ||||||
| 		try { | 		try { | ||||||
| 			// Fetch the file. Add headers when defined. 
 | 			// Fetch the file. Add headers when defined. 
 | ||||||
| 			CONNECT = await (((typeof HEADERS).includes(`undef`)) ? fetch(URL) : fetch(URL, {method: `POST`, headers: HEADERS})); | 			CONNECT = await fetch(URL, {method: `POST`, headers: HEADERS}); | ||||||
| 	 | 			 | ||||||
| 			if (CONNECT.ok && !VERIFY_ONLY) { | 			if (CONNECT.ok && !VERIFY_ONLY) { | ||||||
| 				DATA = await CONNECT[(TYPE.toLowerCase().includes('blob')) ? `blob` : `text`](); | 				DATA = await CONNECT[(TYPE.toLowerCase().includes('blob')) ? `blob` : `text`](); | ||||||
| 			 | 			 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue