forked from MapComplete/MapComplete
Add header options to downloadJSON
This commit is contained in:
parent
a2f3b967b7
commit
4bbcda1621
1 changed files with 7 additions and 4 deletions
|
@ -48,19 +48,22 @@ export default class ScriptUtils {
|
|||
})
|
||||
}
|
||||
|
||||
public static DownloadJSON(url): Promise<any> {
|
||||
public static DownloadJSON(url, options?: {
|
||||
headers: any
|
||||
}): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
||||
const headers = options?.headers ?? {}
|
||||
headers.accept = "application/json"
|
||||
|
||||
const urlObj = new URL(url)
|
||||
https.get({
|
||||
host: urlObj.host,
|
||||
path: urlObj.pathname + urlObj.search,
|
||||
|
||||
port: urlObj.port,
|
||||
headers: {
|
||||
"accept": "application/json"
|
||||
}
|
||||
headers: headers
|
||||
}, (res) => {
|
||||
const parts: string[] = []
|
||||
res.setEncoding('utf8');
|
||||
|
|
Loading…
Reference in a new issue