Skip to main content

Abstract Class: HttpExecutor<T>

Extended by​

Type Parameters​

T​

T extends Request

Constructors​

Constructor​

new HttpExecutor<T>(crossOriginHeaderPolicy?): HttpExecutor<T>

Parameters​

crossOriginHeaderPolicy?​

CrossOriginHeaderPolicy = dropSensitiveHeaders

chooses the headers each redirect to another origin sends on; the default leaves out the credential-bearing ones (see addSensitiveRedirectHeader).

Returns​

HttpExecutor<T>

Properties​

crossOriginHeaderPolicy​

readonly crossOriginHeaderPolicy: CrossOriginHeaderPolicy = dropSensitiveHeaders

chooses the headers each redirect to another origin sends on; the default leaves out the credential-bearing ones (see addSensitiveRedirectHeader).


maxRedirects​

protected readonly maxRedirects: 10 = 10

Methods​

addErrorAndTimeoutHandlers()​

addErrorAndTimeoutHandlers(request, reject, timeout?): void

Parameters​

request​

any

reject​

(error) => void

timeout?​

number = ...

Returns​

void


addRedirectHandlers()​

addRedirectHandlers(request, options, reject, redirectCount, handler): void

Follows the redirects of request when it reports them as events instead of 3xx responses (Electron's net with redirect: "manual", see ElectronHttpExecutor): the request is aborted and handler gets the options for the redirect target from HttpExecutor.prepareRedirectUrlOptions (with HttpExecutor.crossOriginHeaderPolicy), or reject gets the too-many-redirects error when redirectCount, the number of redirects already followed, has reached the limit. Node.js requests answer a redirect with a 3xx response, so this does nothing here.

Parameters​

request​

any

options​

ApiRequestOptions

reject​

(error) => void

redirectCount​

number

handler​

(options) => void

Returns​

void


createMaxRedirectError()​

protected createMaxRedirectError(): Error

Returns​

Error


createRequest()​

abstract createRequest(options, callback): T

Parameters​

options​

RequestOptions

callback​

(response) => void

Returns​

T


doApiRequest()​

doApiRequest(options, cancellationToken, requestProcessor, redirectCount?): Promise<string>

Parameters​

options​

ApiRequestOptions

cancellationToken​

CancellationToken

requestProcessor​

(request, reject) => void

redirectCount?​

number = 0

Returns​

Promise<string>


doDownload()​

protected doDownload(requestOptions, options, redirectCount): void

Parameters​

requestOptions​

ApiRequestOptions

options​

DownloadCallOptions

redirectCount​

number

Returns​

void


downloadToBuffer()​

downloadToBuffer(url, options): Promise<Buffer<ArrayBufferLike>>

Downloads url into memory: at most 500 MB, or options.maxSize bytes when that is smaller (see DownloadOptions.maxSize). A response past the limit fails the download with ERR_UPDATER_DOWNLOAD_SIZE_EXCEEDED as soon as it passes it, and its request is aborted before the rest is received.

Parameters​

url​

URL

options​

DownloadOptions

Returns​

Promise<Buffer<ArrayBufferLike>>


request()​

request(options, cancellationToken?, data?): Promise<string | null>

Parameters​

options​

ApiRequestOptions

cancellationToken?​

CancellationToken = ...

data?​

{[name: string]: any; } | null

Returns​

Promise<string | null>


crossOriginHeaders()​

static crossOriginHeaders(headers, ownHeaders, hop, crossOriginHeaderPolicy): OutgoingHttpHeaders

The headers to send to hop.to for a request whose headers are meant for hop.from: headers itself when to is on the same origin (see HttpExecutor.isCrossOrigin), without calling crossOriginHeaderPolicy; else the ones crossOriginHeaderPolicy returns, and the request's ownHeaders it left out. A Host header is never sent to another origin: it is removed before the policy is asked, and from what it returns, since Electron's net connects to a Host header's value instead of hop.to. Never mutates headers; what crossOriginHeaderPolicy throws fails the request. The headers are copied with filterHeaders.

Parameters​

headers​

OutgoingHttpHeaders

ownHeaders​

OutgoingHttpHeaders | null | undefined

hop​

CrossOriginHop

crossOriginHeaderPolicy​

CrossOriginHeaderPolicy

Returns​

OutgoingHttpHeaders


isCrossOrigin()​

static isCrossOrigin(originUrl, targetUrl): boolean

Whether targetUrl is on another origin than originUrl for the purpose of sending credentials: another host, port or scheme, except an http → https upgrade of the same host on the default ports.

Parameters​

originUrl​

URL

targetUrl​

URL

Returns​

boolean


prepareRedirectUrlOptions()​

static prepareRedirectUrlOptions(redirectUrl, options, crossOriginHeaderPolicy?): ApiRequestOptions

Options for the request to redirectUrl, redirected from options. When the target is on another origin, the headers are the ones crossOriginHeaderPolicy chooses with the request's own headers added back (see HttpExecutor.crossOriginHeaders), and the auth option, which Node.js sends as an Authorization header for the original origin, is dropped. The default User-Agent and Cache-Control are set after that (see configureRequestOptions).

Parameters​

redirectUrl​

string

options​

ApiRequestOptions

crossOriginHeaderPolicy?​

CrossOriginHeaderPolicy = dropSensitiveHeaders

Returns​

ApiRequestOptions


retryOnServerError()​

static retryOnServerError(task, maxRetries?): Promise<any>

Parameters​

task​

() => Promise<any>

maxRetries?​

number = 3

Returns​

Promise<any>