@@ -8,6 +8,7 @@ import { ProgressCallbackTransform } from "./ProgressCallbackTransform"
8
8
import { safeLoad } from "js-yaml"
9
9
import { EventEmitter } from "events"
10
10
import { Socket } from "net"
11
+ import { CancellationToken } from "./CancellationToken"
11
12
12
13
export interface RequestHeaders {
13
14
[ key : string ] : any
@@ -23,9 +24,12 @@ export interface Response extends EventEmitter {
23
24
}
24
25
25
26
export interface DownloadOptions {
26
- headers ?: RequestHeaders | null
27
- skipDirCreation ?: boolean
28
- sha2 ?: string
27
+ readonly headers ?: RequestHeaders | null
28
+ readonly skipDirCreation ?: boolean
29
+ readonly sha2 ?: string | null
30
+
31
+ readonly cancellationToken : CancellationToken
32
+
29
33
onProgress ?( progress : any ) : void
30
34
}
31
35
@@ -62,22 +66,22 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
62
66
protected readonly maxRedirects = 10
63
67
protected readonly debug = _debug ( "electron-builder" )
64
68
65
- request < T > ( options : RequestOptions , data ?: { [ name : string ] : any ; } | null ) : Promise < T > {
69
+ request < T > ( options : RequestOptions , cancellationToken : CancellationToken , data ?: { [ name : string ] : any ; } | null ) : Promise < T > {
66
70
configureRequestOptions ( options )
67
71
const encodedData = data == null ? undefined : new Buffer ( JSON . stringify ( data ) )
68
72
if ( encodedData != null ) {
69
73
options . method = "post"
70
74
options . headers ! [ "Content-Type" ] = "application/json"
71
75
options . headers ! [ "Content-Length" ] = encodedData . length
72
76
}
73
- return this . doApiRequest < T > ( < REQUEST_OPTS > options , it => ( < any > it ) . end ( encodedData ) , 0 )
77
+ return this . doApiRequest < T > ( < REQUEST_OPTS > options , cancellationToken , it => ( < any > it ) . end ( encodedData ) , 0 )
74
78
}
75
79
76
- protected abstract doApiRequest < T > ( options : REQUEST_OPTS , requestProcessor : ( request : REQUEST , reject : ( error : Error ) => void ) => void , redirectCount : number ) : Promise < T >
80
+ protected abstract doApiRequest < T > ( options : REQUEST_OPTS , cancellationToken : CancellationToken , requestProcessor : ( request : REQUEST , reject : ( error : Error ) => void ) => void , redirectCount : number ) : Promise < T >
77
81
78
82
abstract download ( url : string , destination : string , options ?: DownloadOptions | null ) : Promise < string >
79
83
80
- protected handleResponse ( response : Response , options : RequestOptions , resolve : ( data ?: any ) => void , reject : ( error : Error ) => void , redirectCount : number , requestProcessor : ( request : REQUEST , reject : ( error : Error ) => void ) => void ) {
84
+ protected handleResponse ( response : Response , options : RequestOptions , cancellationToken : CancellationToken , resolve : ( data ?: any ) => void , reject : ( error : Error ) => void , redirectCount : number , requestProcessor : ( request : REQUEST , reject : ( error : Error ) => void ) => void ) {
81
85
if ( this . debug . enabled ) {
82
86
this . debug ( `Response status: ${ response . statusCode } ${ response . statusMessage } , request options: ${ dumpRequestOptions ( options ) } ` )
83
87
}
@@ -104,7 +108,7 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
104
108
return
105
109
}
106
110
107
- this . doApiRequest ( < REQUEST_OPTS > Object . assign ( { } , options , parseUrl ( redirectUrl ) ) , requestProcessor , redirectCount )
111
+ this . doApiRequest ( < REQUEST_OPTS > Object . assign ( { } , options , parseUrl ( redirectUrl ) ) , cancellationToken , requestProcessor , redirectCount )
108
112
. then ( resolve )
109
113
. catch ( reject )
110
114
@@ -203,8 +207,8 @@ class DigestTransform extends Transform {
203
207
}
204
208
}
205
209
206
- export function request < T > ( options : RequestOptions , data ?: { [ name : string ] : any ; } | null ) : Promise < T > {
207
- return executorHolder . httpExecutor . request ( options , data )
210
+ export function request < T > ( options : RequestOptions , cancellationToken : CancellationToken , data ?: { [ name : string ] : any ; } | null ) : Promise < T > {
211
+ return executorHolder . httpExecutor . request ( options , cancellationToken , data )
208
212
}
209
213
210
214
function checkSha2 ( sha2Header : string | null | undefined , sha2 : string | null | undefined , callback : ( error : Error | null ) => void ) : boolean {
@@ -245,7 +249,7 @@ function configurePipes(options: DownloadOptions, response: any, destination: st
245
249
if ( options . onProgress != null ) {
246
250
const contentLength = safeGetHeader ( response , "content-length" )
247
251
if ( contentLength != null ) {
248
- streams . push ( new ProgressCallbackTransform ( parseInt ( contentLength , 10 ) , options . onProgress ) )
252
+ streams . push ( new ProgressCallbackTransform ( parseInt ( contentLength , 10 ) , options . cancellationToken , options . onProgress ) )
249
253
}
250
254
}
251
255
0 commit comments