Archived
1
0

Compress when sending client-side extension tars

This commit is contained in:
Asher
2020-02-28 14:25:28 -06:00
parent a8914b025f
commit 88cab27165
3 changed files with 22 additions and 10 deletions

View File

@ -174,7 +174,7 @@ export class VscodeHttpProvider extends HttpProvider {
break
case "/tar":
if (typeof route.query.path === "string") {
return this.getTarredResource(route.query.path)
return this.getTarredResource(request, route.query.path)
}
break
case "/webview":

View File

@ -11,6 +11,7 @@ import { Readable } from "stream"
import * as tarFs from "tar-fs"
import * as tls from "tls"
import * as url from "url"
import * as zlib from "zlib"
import { HttpCode, HttpError } from "../common/http"
import { normalize, Options, plural, split } from "../common/util"
import { SocketProxyProvider } from "./socket"
@ -222,9 +223,20 @@ export abstract class HttpProvider {
/**
* Tar up and stream a directory.
*/
protected async getTarredResource(...parts: string[]): Promise<HttpResponse> {
protected async getTarredResource(request: http.IncomingMessage, ...parts: string[]): Promise<HttpResponse> {
const filePath = path.join(...parts)
return { stream: tarFs.pack(filePath), filePath, mime: "application/tar", cache: true }
let stream: Readable = tarFs.pack(filePath)
const headers: http.OutgoingHttpHeaders = {}
if (request.headers["accept-encoding"] && request.headers["accept-encoding"].includes("gzip")) {
logger.debug("gzipping tar", field("filePath", filePath))
const compress = zlib.createGzip()
stream.pipe(compress)
stream.on("error", (error) => compress.destroy(error))
stream.on("close", () => compress.end())
stream = compress
headers["content-encoding"] = "gzip"
}
return { stream, filePath, mime: "application/gzip", cache: true, headers }
}
/**