1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getNetSession = getNetSession;
|
7 | exports.ElectronHttpExecutor = exports.NET_SESSION_NAME = void 0;
|
8 |
|
9 | function _builderUtilRuntime() {
|
10 | const data = require("builder-util-runtime");
|
11 |
|
12 | _builderUtilRuntime = function () {
|
13 | return data;
|
14 | };
|
15 |
|
16 | return data;
|
17 | }
|
18 |
|
19 | function _electron() {
|
20 | const data = require("electron");
|
21 |
|
22 | _electron = function () {
|
23 | return data;
|
24 | };
|
25 |
|
26 | return data;
|
27 | }
|
28 |
|
29 | const NET_SESSION_NAME = "electron-updater";
|
30 | exports.NET_SESSION_NAME = NET_SESSION_NAME;
|
31 |
|
32 | function getNetSession() {
|
33 | return _electron().session.fromPartition(NET_SESSION_NAME, {
|
34 | cache: false
|
35 | });
|
36 | }
|
37 |
|
38 | class ElectronHttpExecutor extends _builderUtilRuntime().HttpExecutor {
|
39 | constructor(proxyLoginCallback) {
|
40 | super();
|
41 | this.proxyLoginCallback = proxyLoginCallback;
|
42 | this.cachedSession = null;
|
43 | }
|
44 |
|
45 | async download(url, destination, options) {
|
46 | return await options.cancellationToken.createPromise((resolve, reject, onCancel) => {
|
47 | const requestOptions = {
|
48 | headers: options.headers || undefined,
|
49 | redirect: "manual"
|
50 | };
|
51 | (0, _builderUtilRuntime().configureRequestUrl)(url, requestOptions);
|
52 | (0, _builderUtilRuntime().configureRequestOptions)(requestOptions);
|
53 | this.doDownload(requestOptions, {
|
54 | destination,
|
55 | options,
|
56 | onCancel,
|
57 | callback: error => {
|
58 | if (error == null) {
|
59 | resolve(destination);
|
60 | } else {
|
61 | reject(error);
|
62 | }
|
63 | },
|
64 | responseHandler: null
|
65 | }, 0);
|
66 | });
|
67 | }
|
68 |
|
69 | createRequest(options, callback) {
|
70 |
|
71 | if (options.headers && options.headers.Host) {
|
72 |
|
73 | options.host = options.headers.Host;
|
74 |
|
75 | delete options.headers.Host;
|
76 | }
|
77 |
|
78 |
|
79 | if (this.cachedSession == null) {
|
80 | this.cachedSession = getNetSession();
|
81 | }
|
82 |
|
83 | const request = _electron().net.request({ ...options,
|
84 | session: this.cachedSession
|
85 | });
|
86 |
|
87 | request.on("response", callback);
|
88 |
|
89 | if (this.proxyLoginCallback != null) {
|
90 | request.on("login", this.proxyLoginCallback);
|
91 | }
|
92 |
|
93 | return request;
|
94 | }
|
95 |
|
96 | addRedirectHandlers(request, options, reject, redirectCount, handler) {
|
97 | request.on("redirect", (statusCode, method, redirectUrl) => {
|
98 |
|
99 |
|
100 | request.abort();
|
101 |
|
102 | if (redirectCount > this.maxRedirects) {
|
103 | reject(this.createMaxRedirectError());
|
104 | } else {
|
105 | handler(_builderUtilRuntime().HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options));
|
106 | }
|
107 | });
|
108 | }
|
109 |
|
110 | } exports.ElectronHttpExecutor = ElectronHttpExecutor;
|
111 |
|
112 |
|
\ | No newline at end of file |