Fixed HTTP header related issues causing hangs
This commit is contained in:
parent
95b6076229
commit
415e53904b
@ -15,7 +15,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
|
|
||||||
private async authenticatedFetch(
|
private async authenticatedFetch(
|
||||||
url: string,
|
url: string,
|
||||||
options: any
|
options: any,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
if (this.token) {
|
if (this.token) {
|
||||||
options.headers = options.headers || {};
|
options.headers = options.headers || {};
|
||||||
@ -40,7 +40,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
|
|
||||||
async readFile(
|
async readFile(
|
||||||
name: string,
|
name: string,
|
||||||
encoding: FileEncoding
|
encoding: FileEncoding,
|
||||||
): Promise<{ data: FileData; meta: FileMeta }> {
|
): Promise<{ data: FileData; meta: FileMeta }> {
|
||||||
let res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
let res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@ -76,7 +76,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
name: string,
|
name: string,
|
||||||
encoding: FileEncoding,
|
encoding: FileEncoding,
|
||||||
data: FileData,
|
data: FileData,
|
||||||
selfUpdate?: boolean
|
selfUpdate?: boolean,
|
||||||
): Promise<FileMeta> {
|
): Promise<FileMeta> {
|
||||||
let body: any = null;
|
let body: any = null;
|
||||||
|
|
||||||
@ -122,9 +122,9 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
private responseToMeta(name: string, res: Response): FileMeta {
|
private responseToMeta(name: string, res: Response): FileMeta {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
size: +res.headers.get("Content-length")!,
|
size: +res.headers.get("X-Content-Length")!,
|
||||||
contentType: res.headers.get("Content-type")!,
|
contentType: res.headers.get("Content-type")!,
|
||||||
lastModified: +(res.headers.get("Last-Modified") || "0"),
|
lastModified: +(res.headers.get("X-Last-Modified") || "0"),
|
||||||
perm: (res.headers.get("X-Permission") as "rw" | "ro") || "rw",
|
perm: (res.headers.get("X-Permission") as "rw" | "ro") || "rw",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(args),
|
body: JSON.stringify(args),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (req.status !== 200) {
|
if (req.status !== 200) {
|
||||||
let error = await req.text();
|
let error = await req.text();
|
||||||
@ -156,7 +156,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
plug: Plug<any>,
|
plug: Plug<any>,
|
||||||
env: string,
|
env: string,
|
||||||
name: string,
|
name: string,
|
||||||
args: any[]
|
args: any[],
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
// Invoke locally
|
// Invoke locally
|
||||||
if (!env || env === "client") {
|
if (!env || env === "client") {
|
||||||
@ -171,7 +171,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(args),
|
body: JSON.stringify(args),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (req.status !== 200) {
|
if (req.status !== 200) {
|
||||||
let error = await req.text();
|
let error = await req.text();
|
||||||
|
@ -39,6 +39,7 @@ import spaceSyscalls from "./syscalls/space.ts";
|
|||||||
import { systemSyscalls } from "./syscalls/system.ts";
|
import { systemSyscalls } from "./syscalls/system.ts";
|
||||||
import { AssetBundlePlugSpacePrimitives } from "../common/spaces/asset_bundle_space_primitives.ts";
|
import { AssetBundlePlugSpacePrimitives } from "../common/spaces/asset_bundle_space_primitives.ts";
|
||||||
import assetSyscalls from "../plugos/syscalls/asset.ts";
|
import assetSyscalls from "../plugos/syscalls/asset.ts";
|
||||||
|
import { FlashServer } from "https://deno.land/x/oak@v11.1.0/mod.ts";
|
||||||
|
|
||||||
export type ServerOptions = {
|
export type ServerOptions = {
|
||||||
port: number;
|
port: number;
|
||||||
@ -65,7 +66,7 @@ export class HttpServer {
|
|||||||
|
|
||||||
constructor(options: ServerOptions) {
|
constructor(options: ServerOptions) {
|
||||||
this.port = options.port;
|
this.port = options.port;
|
||||||
this.app = new Application();
|
this.app = new Application(); //{ serverConstructor: FlashServer });
|
||||||
this.assetBundle = options.assetBundle;
|
this.assetBundle = options.assetBundle;
|
||||||
this.password = options.password;
|
this.password = options.password;
|
||||||
|
|
||||||
@ -247,11 +248,11 @@ export class HttpServer {
|
|||||||
|
|
||||||
// Simple password authentication
|
// Simple password authentication
|
||||||
if (this.password) {
|
if (this.password) {
|
||||||
this.app.use(({ request, response }, next) => {
|
this.app.use(async ({ request, response }, next) => {
|
||||||
if (
|
if (
|
||||||
request.headers.get("Authorization") === `Bearer ${this.password}`
|
request.headers.get("Authorization") === `Bearer ${this.password}`
|
||||||
) {
|
) {
|
||||||
return next();
|
await next();
|
||||||
} else {
|
} else {
|
||||||
response.status = 401;
|
response.status = 401;
|
||||||
response.body = "Unauthorized";
|
response.body = "Unauthorized";
|
||||||
@ -407,7 +408,7 @@ function buildFsRouter(spacePrimitives: SpacePrimitives): Router {
|
|||||||
);
|
);
|
||||||
response.status = 200;
|
response.status = 200;
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
"Last-Modified",
|
"X-Last-Modified",
|
||||||
"" + attachmentData.meta.lastModified,
|
"" + attachmentData.meta.lastModified,
|
||||||
);
|
);
|
||||||
response.headers.set("X-Permission", attachmentData.meta.perm);
|
response.headers.set("X-Permission", attachmentData.meta.perm);
|
||||||
@ -431,9 +432,9 @@ function buildFsRouter(spacePrimitives: SpacePrimitives): Router {
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
response.status = 200;
|
response.status = 200;
|
||||||
response.headers.set("Last-Modified", "" + meta.lastModified);
|
|
||||||
response.headers.set("Content-Type", meta.contentType);
|
response.headers.set("Content-Type", meta.contentType);
|
||||||
response.headers.set("Content-Length", "" + meta.size);
|
response.headers.set("X-Last-Modified", "" + meta.lastModified);
|
||||||
|
response.headers.set("X-Content-Length", "" + meta.size);
|
||||||
response.headers.set("X-Permission", meta.perm);
|
response.headers.set("X-Permission", meta.perm);
|
||||||
response.body = "OK";
|
response.body = "OK";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -441,18 +442,21 @@ function buildFsRouter(spacePrimitives: SpacePrimitives): Router {
|
|||||||
response.body = "Write failed";
|
response.body = "Write failed";
|
||||||
console.error("Pipeline failed", err);
|
console.error("Pipeline failed", err);
|
||||||
}
|
}
|
||||||
|
console.log("Done with put", name);
|
||||||
})
|
})
|
||||||
.options("\/(.+)", async ({ response, params }, next) => {
|
.options("\/(.+)", async ({ response, params }) => {
|
||||||
const name = params[0];
|
const name = params[0];
|
||||||
try {
|
try {
|
||||||
const meta = await spacePrimitives.getFileMeta(name);
|
const meta = await spacePrimitives.getFileMeta(name);
|
||||||
response.status = 200;
|
response.status = 200;
|
||||||
response.headers.set("Last-Modified", "" + meta.lastModified);
|
|
||||||
response.headers.set("Content-Type", meta.contentType);
|
response.headers.set("Content-Type", meta.contentType);
|
||||||
response.headers.set("Content-Length", "" + meta.size);
|
response.headers.set("X-Last-Modified", "" + meta.lastModified);
|
||||||
|
response.headers.set("X-Content-Length", "" + meta.size);
|
||||||
response.headers.set("X-Permission", meta.perm);
|
response.headers.set("X-Permission", meta.perm);
|
||||||
} catch {
|
} catch (err) {
|
||||||
next();
|
response.status = 500;
|
||||||
|
response.body = "Options failed";
|
||||||
|
console.error("Options failed", err);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.delete("\/(.+)", async ({ response, params }) => {
|
.delete("\/(.+)", async ({ response, params }) => {
|
||||||
|
@ -23,7 +23,7 @@ const port = +args.port;
|
|||||||
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
|
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
|
||||||
import { AssetBundle } from "../plugos/asset_bundle_reader.ts";
|
import { AssetBundle } from "../plugos/asset_bundle_reader.ts";
|
||||||
|
|
||||||
console.log("Pages dir", pagesPath);
|
console.log("Pages folder:", pagesPath);
|
||||||
|
|
||||||
const httpServer = new HttpServer({
|
const httpServer = new HttpServer({
|
||||||
port: port,
|
port: port,
|
||||||
|
@ -272,9 +272,6 @@ export class Editor {
|
|||||||
|
|
||||||
save(immediate = false): Promise<void> {
|
save(immediate = false): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.viewState.unsavedChanges) {
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
if (this.saveTimeout) {
|
if (this.saveTimeout) {
|
||||||
clearTimeout(this.saveTimeout);
|
clearTimeout(this.saveTimeout);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
An attempt at documenting of the changes/new features introduced in each release.
|
An attempt at documenting of the changes/new features introduced in each release.
|
||||||
|
|
||||||
|
---
|
||||||
|
## Deno release
|
||||||
|
* The entire repo has been migrated to [Deno](https://deno.land)
|
||||||
|
* This may temporarily break some things.
|
||||||
|
* If somehow you’re experiencing trouble, try the following:
|
||||||
|
* Delete all files under `_plug` in your pages folder, e.g. with `rm -rf pages/_plug`.
|
||||||
|
* Delete your `data.db`
|
||||||
|
* Changes:
|
||||||
|
* `PLUGS` is now longer required
|
||||||
|
* `PLUGS` no longer supports `builtin:` plug URLs, all builtins are automatically loaded and no longer should be listed.
|
||||||
|
* Plugs no longer should be built with node and npm, PRs will be issued to all existing plugs later to help with this transition.
|
||||||
|
* Know breakages:
|
||||||
|
* Full text search is not yet implemented (the SQLite used does not support it right now)
|
||||||
|
* Github auth has not been ported (yet)
|
||||||
|
* Technical changes:
|
||||||
|
* Server runs on Deno (and Oak instead of Express)
|
||||||
|
* Client is now built with ESBuild
|
||||||
|
* React has been replaced with Preact
|
||||||
|
* Package management in Deno works based on http imports, so npm is no longer used.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 0.0.35
|
## 0.0.35
|
||||||
@ -66,4 +86,4 @@ An attempt at documenting of the changes/new features introduced in each release
|
|||||||
4. The currently open page (at the bottom)
|
4. The currently open page (at the bottom)
|
||||||
* Filter boxes (used for the page switching and command palette among other things) now also support PgUp, PgDown, Home and End and have some visual glitches fixed as well.
|
* Filter boxes (used for the page switching and command palette among other things) now also support PgUp, PgDown, Home and End and have some visual glitches fixed as well.
|
||||||
* Reverted exposing an empty `window` object to sandboxes running in workers and node.js (introduced in 0.0.28)
|
* Reverted exposing an empty `window` object to sandboxes running in workers and node.js (introduced in 0.0.28)
|
||||||
* Renamed Markdown-preview related commands to something more consistent
|
* Renamed Markdown-preview related commands to something more consistentnt
|
@ -1,8 +1,8 @@
|
|||||||
/fs/_plug/*
|
/fs/_plug/*
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Last-Modified: 0
|
X-Last-Modified: 0
|
||||||
X-Permission: ro
|
X-Permission: ro
|
||||||
/fs/*
|
/fs/*
|
||||||
Content-Type: text/markdown
|
Content-Type: text/markdown
|
||||||
Last-Modified: 0
|
X-Last-Modified: 0
|
||||||
X-Permission: rw
|
X-Permission: rw
|
||||||
|
Loading…
Reference in New Issue
Block a user