Skip to content

Commit 88cab27

Browse files
committed
Compress when sending client-side extension tars
1 parent a8914b0 commit 88cab27

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

ci/vscode.patch

+7-7
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ index 2d8b725ff2..a8d93a17ca 100644
119119
unique-stream@^2.0.2:
120120
version "2.2.1"
121121
diff --git a/package.json b/package.json
122-
index fde05321d2..1a7ed2fa47 100644
122+
index fde05321d2..2427e7d4ae 100644
123123
--- a/package.json
124124
+++ b/package.json
125125
@@ -32,6 +32,9 @@
@@ -128,7 +128,7 @@ index fde05321d2..1a7ed2fa47 100644
128128
"dependencies": {
129129
+ "@coder/logger": "^1.1.12",
130130
+ "@coder/node-browser": "^1.0.8",
131-
+ "@coder/requirefs": "^1.1.4",
131+
+ "@coder/requirefs": "^1.1.5",
132132
"applicationinsights": "1.0.8",
133133
"chokidar": "3.2.3",
134134
"graceful-fs": "4.1.11",
@@ -3109,7 +3109,7 @@ index 82626a55c7..5d3ee1b69b 100644
31093109
union-value@^1.0.0:
31103110
version "1.0.1"
31113111
diff --git a/yarn.lock b/yarn.lock
3112-
index a98533bad9..19e94f8c4a 100644
3112+
index a98533bad9..f4da0987c9 100644
31133113
--- a/yarn.lock
31143114
+++ b/yarn.lock
31153115
@@ -140,6 +140,23 @@
@@ -3126,10 +3126,10 @@ index a98533bad9..19e94f8c4a 100644
31263126
+ resolved "https://registry.yarnpkg.com/@coder/node-browser/-/node-browser-1.0.8.tgz#c22f581b089ad7d95ad1362fd351c57b7fbc6e70"
31273127
+ integrity sha512-NLF9sYMRCN9WK1C224pHax1Cay3qKypg25BhVg7VfNbo3Cpa3daata8RF/rT8JK3lPsu8PmFgDRQjzGC9X1Lrw==
31283128
+
3129-
+"@coder/requirefs@^1.1.4":
3130-
+ version "1.1.4"
3131-
+ resolved "https://registry.yarnpkg.com/@coder/requirefs/-/requirefs-1.1.4.tgz#ca59223a396021f2f606f71b833c43dbba06b10b"
3132-
+ integrity sha512-E+WB3Wvr31v7eqWdItBW4eVQ0tWr4iKH6qjzCMnRxTsbiiNzLgtDzRBYt/3KxnPrtWXXX6Fn02Ut933soZXJ+g==
3129+
+"@coder/requirefs@^1.1.5":
3130+
+ version "1.1.5"
3131+
+ resolved "https://registry.yarnpkg.com/@coder/requirefs/-/requirefs-1.1.5.tgz#259db370d563a79a96fb150bc9d69c7db6edc9fb"
3132+
+ integrity sha512-3jB47OFCql9+9FI6Vc4YX0cfFnG5rxBfrZUH45S4XYtYGOz+/Xl4h4d2iMk50b7veHkeSWGlB4VHC3UZ16zuYQ==
31333133
+ optionalDependencies:
31343134
+ jszip "2.6.0"
31353135
+

src/node/app/vscode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class VscodeHttpProvider extends HttpProvider {
174174
break
175175
case "/tar":
176176
if (typeof route.query.path === "string") {
177-
return this.getTarredResource(route.query.path)
177+
return this.getTarredResource(request, route.query.path)
178178
}
179179
break
180180
case "/webview":

src/node/http.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Readable } from "stream"
1111
import * as tarFs from "tar-fs"
1212
import * as tls from "tls"
1313
import * as url from "url"
14+
import * as zlib from "zlib"
1415
import { HttpCode, HttpError } from "../common/http"
1516
import { normalize, Options, plural, split } from "../common/util"
1617
import { SocketProxyProvider } from "./socket"
@@ -222,9 +223,20 @@ export abstract class HttpProvider {
222223
/**
223224
* Tar up and stream a directory.
224225
*/
225-
protected async getTarredResource(...parts: string[]): Promise<HttpResponse> {
226+
protected async getTarredResource(request: http.IncomingMessage, ...parts: string[]): Promise<HttpResponse> {
226227
const filePath = path.join(...parts)
227-
return { stream: tarFs.pack(filePath), filePath, mime: "application/tar", cache: true }
228+
let stream: Readable = tarFs.pack(filePath)
229+
const headers: http.OutgoingHttpHeaders = {}
230+
if (request.headers["accept-encoding"] && request.headers["accept-encoding"].includes("gzip")) {
231+
logger.debug("gzipping tar", field("filePath", filePath))
232+
const compress = zlib.createGzip()
233+
stream.pipe(compress)
234+
stream.on("error", (error) => compress.destroy(error))
235+
stream.on("close", () => compress.end())
236+
stream = compress
237+
headers["content-encoding"] = "gzip"
238+
}
239+
return { stream, filePath, mime: "application/gzip", cache: true, headers }
228240
}
229241

230242
/**

0 commit comments

Comments
 (0)