Skip to content

Commit 02a96f4

Browse files
committed
fix: always revalidate cache
Close #1186
1 parent eee3b71 commit 02a96f4

File tree

14 files changed

+46
-57
lines changed

14 files changed

+46
-57
lines changed

.idea/dictionaries/develar.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"path-sort": "^0.1.0",
7474
"source-map-support": "^0.4.10",
7575
"ts-babel": "^1.3.5",
76-
"tslint": "^4.3.1",
76+
"tslint": "^4.4.2",
7777
"typescript": "^2.1.5",
7878
"whitespace": "^2.1.0"
7979
},

packages/electron-builder-http/src/bintray.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BintrayOptions } from "./publishOptions"
22
import { request, configureRequestOptions } from "./httpExecutor"
33

4-
export function bintrayRequest<T>(path: string, auth: string | null, data: {[name: string]: any; } | null = null, method?: string): Promise<T> {
4+
export function bintrayRequest<T>(path: string, auth: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise<T> {
55
return request<T>(configureRequestOptions({hostname: "api.bintray.com", path: path}, auth, method), data)
66
}
77

packages/electron-builder-http/src/httpExecutor.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,14 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
6363
protected readonly debug = _debug("electron-builder")
6464

6565
request<T>(options: RequestOptions, data?: { [name: string]: any; } | null): Promise<T> {
66-
options = Object.assign({headers: {"User-Agent": "electron-builder"}}, options)
67-
66+
configureRequestOptions(options)
6867
const encodedData = data == null ? undefined : new Buffer(JSON.stringify(data))
6968
if (encodedData != null) {
7069
options.method = "post"
71-
if (options.headers == null) {
72-
options.headers = {}
73-
}
74-
75-
options.headers["Content-Type"] = "application/json"
76-
options.headers["Content-Length"] = encodedData.length
70+
options.headers!["Content-Type"] = "application/json"
71+
options.headers!["Content-Length"] = encodedData.length
7772
}
78-
return this.doApiRequest<T>(<any>options, it => (<any>it).end(encodedData), 0)
73+
return this.doApiRequest<T>(<REQUEST_OPTS>options, it => (<any>it).end(encodedData), 0)
7974
}
8075

8176
protected abstract doApiRequest<T>(options: REQUEST_OPTS, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount: number): Promise<T>
@@ -270,7 +265,7 @@ function configurePipes(options: DownloadOptions, response: any, destination: st
270265
fileOut.on("finish", () => (<any>fileOut.close)(callback))
271266
}
272267

273-
export function configureRequestOptions(options: RequestOptions, token: string | null, method?: string): RequestOptions {
268+
export function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT"): RequestOptions {
274269
if (method != null) {
275270
options.method = method
276271
}
@@ -286,6 +281,10 @@ export function configureRequestOptions(options: RequestOptions, token: string |
286281
if (headers["User-Agent"] == null) {
287282
headers["User-Agent"] = "electron-builder"
288283
}
284+
285+
if ((method == null || method === "GET") || headers["Cache-Control"] == null) {
286+
headers["Cache-Control"] = "no-cache"
287+
}
289288
return options
290289
}
291290

packages/electron-builder/src/publish/BintrayPublisher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class BintrayPublisher extends Publisher {
6363
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`,
6464
method: "PUT",
6565
headers: {
66-
"User-Agent": "electron-builder",
6766
"Content-Length": dataLength,
6867
"X-Bintray-Override": "1",
6968
"X-Bintray-Publish": "1",

packages/electron-builder/src/publish/gitHubPublisher.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export class GitHubPublisher extends Publisher {
103103
method: "POST",
104104
headers: {
105105
Accept: "application/vnd.github.v3+json",
106-
"User-Agent": "electron-builder",
107106
"Content-Type": mime.lookup(fileName),
108107
"Content-Length": dataLength
109108
}
@@ -180,7 +179,7 @@ export class GitHubPublisher extends Publisher {
180179
warn(`Cannot delete release ${release.id}`)
181180
}
182181

183-
private githubRequest<T>(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: string): Promise<T> {
182+
private githubRequest<T>(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise<T> {
184183
return this.httpExecutor.request<T>(configureRequestOptions({
185184
hostname: "api.github.com",
186185
path: path,

packages/electron-builder/src/util/nodeHttpExecutor.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import BluebirdPromise from "bluebird-lst-c"
55
import * as path from "path"
66
import { homedir } from "os"
77
import { parse as parseIni } from "ini"
8-
import { HttpExecutor, DownloadOptions } from "electron-builder-http"
8+
import { HttpExecutor, DownloadOptions, configureRequestOptions } from "electron-builder-http"
99
import { RequestOptions } from "https"
1010
import { parse as parseUrl } from "url"
1111

@@ -24,14 +24,12 @@ export class NodeHttpExecutor extends HttpExecutor<RequestOptions, ClientRequest
2424
const agent = await this.httpsAgentPromise
2525
return await new BluebirdPromise<string>((resolve, reject) => {
2626
const parsedUrl = parseUrl(url)
27-
this.doDownload({
27+
this.doDownload(configureRequestOptions({
2828
hostname: parsedUrl.hostname,
2929
path: parsedUrl.path,
30-
headers: Object.assign({
31-
"User-Agent": "electron-builder"
32-
}, options == null ? null : options.headers),
30+
headers: (options == null ? null : options.headers) || undefined,
3331
agent: agent,
34-
}, destination, 0, options || {}, (error: Error) => {
32+
}), destination, 0, options || {}, (error: Error) => {
3533
if (error == null) {
3634
resolve(destination)
3735
}

packages/electron-updater/src/AppUpdater.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export abstract class AppUpdater extends EventEmitter {
3737

3838
public readonly signals = new UpdaterSignal(this)
3939

40-
private appUpdateConfigPath: string | null
40+
private _appUpdateConfigPath: string | null
4141

42-
setUpdateConfigPath(value: string | null) {
42+
set updateConfigPath(value: string | null) {
4343
this.clientPromise = null
44-
this.appUpdateConfigPath = value
44+
this._appUpdateConfigPath = value
4545
}
4646

4747
protected updateAvailable = false
@@ -232,10 +232,10 @@ export abstract class AppUpdater extends EventEmitter {
232232
abstract quitAndInstall(): void
233233

234234
async loadUpdateConfig() {
235-
if (this.appUpdateConfigPath == null) {
236-
this.appUpdateConfigPath = path.join(process.resourcesPath, "app-update.yml")
235+
if (this._appUpdateConfigPath == null) {
236+
this._appUpdateConfigPath = path.join(process.resourcesPath, "app-update.yml")
237237
}
238-
return safeLoad(await readFile(this.appUpdateConfigPath, "utf-8"))
238+
return safeLoad(await readFile(this._appUpdateConfigPath, "utf-8"))
239239
}
240240
}
241241

packages/electron-updater/src/GenericProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class GenericProvider extends Provider<UpdateInfo> {
2222
hostname: this.baseUrl.hostname,
2323
path: `${pathname}${this.baseUrl.search || ""}`,
2424
protocol: this.baseUrl.protocol,
25-
headers: Object.assign({"Cache-Control": "no-cache, no-store, must-revalidate"}, this.requestHeaders)
25+
headers: this.requestHeaders || undefined
2626
}
2727
if (this.baseUrl.port != null) {
2828
options.port = parseInt(this.baseUrl.port, 10)

packages/electron-updater/src/NsisUpdater.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class NsisUpdater extends AppUpdater {
2424
protected async doDownloadUpdate(versionInfo: VersionInfo, fileInfo: FileInfo) {
2525
const downloadOptions: DownloadOptions = {
2626
skipDirCreation: true,
27+
headers: this.requestHeaders || undefined,
2728
}
2829

2930
if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {
@@ -33,9 +34,6 @@ export class NsisUpdater extends AppUpdater {
3334
if (fileInfo != null && fileInfo.sha2 != null) {
3435
downloadOptions.sha2 = fileInfo.sha2
3536
}
36-
if (this.requestHeaders != null) {
37-
downloadOptions.headers = this.requestHeaders
38-
}
3937

4038
const logger = this.logger
4139
const tempDir = await mkdtemp(`${path.join(tmpdir(), "up")}-`)

0 commit comments

Comments
 (0)