Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91d3933eb5 |
+1
-39
@@ -37,12 +37,9 @@ export class DownloadProgress {
|
|||||||
segmentSize: number
|
segmentSize: number
|
||||||
segmentOffset: number
|
segmentOffset: number
|
||||||
receivedBytes: number
|
receivedBytes: number
|
||||||
previouslyReceivedBytes: number
|
|
||||||
lastTimeOfNewBytes?: number
|
|
||||||
startTime: number
|
startTime: number
|
||||||
displayedComplete: boolean
|
displayedComplete: boolean
|
||||||
timeoutHandle?: ReturnType<typeof setTimeout>
|
timeoutHandle?: ReturnType<typeof setTimeout>
|
||||||
abortController?: AbortController
|
|
||||||
|
|
||||||
constructor(contentLength: number) {
|
constructor(contentLength: number) {
|
||||||
this.contentLength = contentLength
|
this.contentLength = contentLength
|
||||||
@@ -50,11 +47,8 @@ export class DownloadProgress {
|
|||||||
this.segmentSize = 0
|
this.segmentSize = 0
|
||||||
this.segmentOffset = 0
|
this.segmentOffset = 0
|
||||||
this.receivedBytes = 0
|
this.receivedBytes = 0
|
||||||
this.previouslyReceivedBytes = 0
|
|
||||||
this.lastTimeOfNewBytes = undefined
|
|
||||||
this.displayedComplete = false
|
this.displayedComplete = false
|
||||||
this.startTime = Date.now()
|
this.startTime = Date.now()
|
||||||
this.abortController = undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +62,6 @@ export class DownloadProgress {
|
|||||||
this.segmentIndex = this.segmentIndex + 1
|
this.segmentIndex = this.segmentIndex + 1
|
||||||
this.segmentSize = segmentSize
|
this.segmentSize = segmentSize
|
||||||
this.receivedBytes = 0
|
this.receivedBytes = 0
|
||||||
this.previouslyReceivedBytes = 0
|
|
||||||
|
|
||||||
core.debug(
|
core.debug(
|
||||||
`Downloading segment at offset ${this.segmentOffset} with length ${this.segmentSize}...`
|
`Downloading segment at offset ${this.segmentOffset} with length ${this.segmentSize}...`
|
||||||
@@ -91,22 +84,6 @@ export class DownloadProgress {
|
|||||||
return this.segmentOffset + this.receivedBytes
|
return this.segmentOffset + this.receivedBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
setLastTimeOfNewBytes(): void {
|
|
||||||
this.lastTimeOfNewBytes = Date.now()
|
|
||||||
}
|
|
||||||
|
|
||||||
getLastTimeOfNewBytes(): number | undefined {
|
|
||||||
return this.lastTimeOfNewBytes
|
|
||||||
}
|
|
||||||
|
|
||||||
setAbortController(abortReference: AbortController): void {
|
|
||||||
this.abortController = abortReference
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerAbortController(): void {
|
|
||||||
this.abortController?.abort()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the download is complete.
|
* Returns true if the download is complete.
|
||||||
*/
|
*/
|
||||||
@@ -148,21 +125,7 @@ export class DownloadProgress {
|
|||||||
*/
|
*/
|
||||||
onProgress(): (progress: TransferProgressEvent) => void {
|
onProgress(): (progress: TransferProgressEvent) => void {
|
||||||
return (progress: TransferProgressEvent) => {
|
return (progress: TransferProgressEvent) => {
|
||||||
if (progress.loadedBytes > this.getTransferredBytes()) {
|
this.setReceivedBytes(progress.loadedBytes)
|
||||||
this.setReceivedBytes(progress.loadedBytes)
|
|
||||||
this.setLastTimeOfNewBytes()
|
|
||||||
} else {
|
|
||||||
// if download hanging for more than 2 minutes
|
|
||||||
if (
|
|
||||||
this.getLastTimeOfNewBytes() !== undefined &&
|
|
||||||
Date.now() - this.getLastTimeOfNewBytes()! > 120000
|
|
||||||
) {
|
|
||||||
this.triggerAbortController()
|
|
||||||
throw new Error(
|
|
||||||
'Aborting cache download as the download has stalled for more than 2 minutes.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +252,6 @@ export async function downloadCacheStorageSDK(
|
|||||||
try {
|
try {
|
||||||
downloadProgress.startDisplayTimer()
|
downloadProgress.startDisplayTimer()
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
downloadProgress.setAbortController(controller)
|
|
||||||
const abortSignal = controller.signal
|
const abortSignal = controller.signal
|
||||||
while (!downloadProgress.isDone()) {
|
while (!downloadProgress.isDone()) {
|
||||||
const segmentStart =
|
const segmentStart =
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ describe('proxy', () => {
|
|||||||
expect(proxyUrl).toBeDefined()
|
expect(proxyUrl).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('getProxyUrl returns proxyUrl if http_proxy has no protocol', () => {
|
||||||
|
process.env['http_proxy'] = 'myproxysvr'
|
||||||
|
const proxyUrl = pm.getProxyUrl(new URL('http://github.com'))
|
||||||
|
expect(proxyUrl?.toString()).toBe('http://myproxysvr/')
|
||||||
|
})
|
||||||
|
|
||||||
it('checkBypass returns true if host as no_proxy list', () => {
|
it('checkBypass returns true if host as no_proxy list', () => {
|
||||||
process.env['no_proxy'] = 'myserver'
|
process.env['no_proxy'] = 'myserver'
|
||||||
const bypass = pm.checkBypass(new URL('https://myserver'))
|
const bypass = pm.checkBypass(new URL('https://myserver'))
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ export function getProxyUrl(reqUrl: URL): URL | undefined {
|
|||||||
})()
|
})()
|
||||||
|
|
||||||
if (proxyVar) {
|
if (proxyVar) {
|
||||||
return new URL(proxyVar)
|
try {
|
||||||
|
return new URL(proxyVar)
|
||||||
|
} catch {
|
||||||
|
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
|
||||||
|
return new URL(`http://${proxyVar}`)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user