@@ -8,6 +8,7 @@ import { ProgressCallbackTransform } from "./ProgressCallbackTransform"
88import { safeLoad } from "js-yaml"
99import { EventEmitter } from "events"
1010import { Socket } from "net"
11+ import { CancellationToken } from "./CancellationToken"
1112
1213export interface RequestHeaders {
1314 [ key : string ] : any
@@ -23,9 +24,12 @@ export interface Response extends EventEmitter {
2324}
2425
2526export 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+
2933 onProgress ?( progress : any ) : void
3034}
3135
@@ -62,22 +66,22 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
6266 protected readonly maxRedirects = 10
6367 protected readonly debug = _debug ( "electron-builder" )
6468
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 > {
6670 configureRequestOptions ( options )
6771 const encodedData = data == null ? undefined : new Buffer ( JSON . stringify ( data ) )
6872 if ( encodedData != null ) {
6973 options . method = "post"
7074 options . headers ! [ "Content-Type" ] = "application/json"
7175 options . headers ! [ "Content-Length" ] = encodedData . length
7276 }
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 )
7478 }
7579
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 >
7781
7882 abstract download ( url : string , destination : string , options ?: DownloadOptions | null ) : Promise < string >
7983
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 ) {
8185 if ( this . debug . enabled ) {
8286 this . debug ( `Response status: ${ response . statusCode } ${ response . statusMessage } , request options: ${ dumpRequestOptions ( options ) } ` )
8387 }
@@ -104,7 +108,7 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
104108 return
105109 }
106110
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 )
108112 . then ( resolve )
109113 . catch ( reject )
110114
@@ -203,8 +207,8 @@ class DigestTransform extends Transform {
203207 }
204208}
205209
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 )
208212}
209213
210214function 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
245249 if ( options . onProgress != null ) {
246250 const contentLength = safeGetHeader ( response , "content-length" )
247251 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 ) )
249253 }
250254 }
251255
0 commit comments