Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d832f61

Browse files
committedMar 16, 2020
Make client-side extensions work at any base
1 parent 88f4b98 commit d832f61

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed
 

‎ci/vscode.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ index 0000000000..0d2e93edae
819819
+}
820820
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
821821
new file mode 100644
822-
index 0000000000..0ba93cc070
822+
index 0000000000..a93381631a
823823
--- /dev/null
824824
+++ b/src/vs/server/browser/worker.ts
825825
@@ -0,0 +1,57 @@
@@ -841,8 +841,8 @@ index 0000000000..0ba93cc070
841841
+ const fetchUri = URI.from({
842842
+ scheme: self.location.protocol.replace(':', ''),
843843
+ authority: self.location.host,
844-
+ path: `${self.location.pathname.replace(/\/static.*\/out\/vs\/workbench\/services\/extensions\/worker\/extensionHostWorkerMain.js$/, '')}/tar`,
845-
+ query: `path=${encodeURIComponent(module.extensionLocation.path)}`,
844+
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
845+
+ query: `tar=${encodeURIComponent(module.extensionLocation.path)}`,
846846
+ });
847847
+ const response = await fetch(fetchUri.toString(true));
848848
+ if (response.status !== 200) {

‎src/node/app/static.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
import { field, logger } from "@coder/logger"
12
import * as http from "http"
3+
import * as path from "path"
4+
import { Readable } from "stream"
5+
import * as tarFs from "tar-fs"
6+
import * as zlib from "zlib"
27
import { HttpProvider, HttpResponse, Route } from "../http"
38

49
/**
5-
* Static file HTTP provider. Static requests do not require authentication and
6-
* they only allow access to resources within the application.
10+
* Static file HTTP provider. Regular static requests (the path is the request
11+
* itself) do not require authentication and they only allow access to resources
12+
* within the application. Requests for tars (the path is in a query parameter)
13+
* do require permissions and can access any directory.
714
*/
815
export class StaticHttpProvider extends HttpProvider {
916
public async handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse> {
1017
this.ensureMethod(request)
18+
19+
if (typeof route.query.tar === "string") {
20+
this.ensureAuthenticated(request)
21+
return this.getTarredResource(request, route.query.tar)
22+
}
23+
1124
const response = await this.getReplacedResource(route)
1225
if (!this.isDev) {
1326
response.cache = true
@@ -30,4 +43,23 @@ export class StaticHttpProvider extends HttpProvider {
3043
}
3144
return this.getResource(this.rootPath, ...split)
3245
}
46+
47+
/**
48+
* Tar up and stream a directory.
49+
*/
50+
private async getTarredResource(request: http.IncomingMessage, ...parts: string[]): Promise<HttpResponse> {
51+
const filePath = path.join(...parts)
52+
let stream: Readable = tarFs.pack(filePath)
53+
const headers: http.OutgoingHttpHeaders = {}
54+
if (request.headers["accept-encoding"] && request.headers["accept-encoding"].includes("gzip")) {
55+
logger.debug("gzipping tar", field("filePath", filePath))
56+
const compress = zlib.createGzip()
57+
stream.pipe(compress)
58+
stream.on("error", (error) => compress.destroy(error))
59+
stream.on("close", () => compress.end())
60+
stream = compress
61+
headers["content-encoding"] = "gzip"
62+
}
63+
return { stream, filePath, mime: "application/x-tar", cache: true, headers }
64+
}
3365
}

‎src/node/app/vscode.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ export class VscodeHttpProvider extends HttpProvider {
155155
return this.getResource(route.query.path)
156156
}
157157
break
158-
case "/tar":
159-
if (typeof route.query.path === "string") {
160-
return this.getTarredResource(request, route.query.path)
161-
}
162-
break
163158
case "/webview":
164159
if (/^\/vscode-resource/.test(route.requestPath)) {
165160
return this.getResource(route.requestPath.replace(/^\/vscode-resource(\/file)?/, ""))

‎src/node/http.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import * as path from "path"
88
import * as querystring from "querystring"
99
import safeCompare from "safe-compare"
1010
import { Readable } from "stream"
11-
import * as tarFs from "tar-fs"
1211
import * as tls from "tls"
1312
import * as url from "url"
14-
import * as zlib from "zlib"
1513
import { HttpCode, HttpError } from "../common/http"
1614
import { normalize, Options, plural, split } from "../common/util"
1715
import { SocketProxyProvider } from "./socket"
@@ -233,25 +231,6 @@ export abstract class HttpProvider {
233231
return { content: await fs.readFile(filePath, "utf8"), filePath }
234232
}
235233

236-
/**
237-
* Tar up and stream a directory.
238-
*/
239-
protected async getTarredResource(request: http.IncomingMessage, ...parts: string[]): Promise<HttpResponse> {
240-
const filePath = path.join(...parts)
241-
let stream: Readable = tarFs.pack(filePath)
242-
const headers: http.OutgoingHttpHeaders = {}
243-
if (request.headers["accept-encoding"] && request.headers["accept-encoding"].includes("gzip")) {
244-
logger.debug("gzipping tar", field("filePath", filePath))
245-
const compress = zlib.createGzip()
246-
stream.pipe(compress)
247-
stream.on("error", (error) => compress.destroy(error))
248-
stream.on("close", () => compress.end())
249-
stream = compress
250-
headers["content-encoding"] = "gzip"
251-
}
252-
return { stream, filePath, mime: "application/x-tar", cache: true, headers }
253-
}
254-
255234
/**
256235
* Helper to error on invalid methods (default GET).
257236
*/

0 commit comments

Comments
 (0)
Please sign in to comment.