@weborigami/origami 0.6.8 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "5.9.3"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.6.8",
20
+ "@weborigami/async-tree": "0.6.9",
21
21
  "@weborigami/json-feed-to-rss": "1.0.1",
22
- "@weborigami/language": "0.6.8",
22
+ "@weborigami/language": "0.6.9",
23
23
  "css-tree": "3.1.0",
24
24
  "graphviz-wasm": "3.0.2",
25
25
  "highlight.js": "11.11.1",
@@ -10,6 +10,8 @@ import {
10
10
  import * as serialize from "../common/serialize.js";
11
11
  import { mediaTypeForExtension } from "./mediaTypes.js";
12
12
 
13
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
14
+
13
15
  /**
14
16
  * Given a resource that was returned from a route, construct an appropriate
15
17
  * HTTP Response indicating what should be sent to the client. Return null
@@ -92,10 +94,19 @@ export default async function constructResponse(request, resource) {
92
94
  mediaType += "; charset=utf-8";
93
95
  body = text;
94
96
  }
95
- } else if (mediaType && SiteMap.mediaTypeIsText(mediaType)) {
96
- // Assume text is encoded in UTF-8.
97
- body = toString(resource);
98
- mediaType += "; charset=utf-8";
97
+ } else if (
98
+ body instanceof TypedArray &&
99
+ mediaType &&
100
+ SiteMap.mediaTypeIsText(mediaType) &&
101
+ !mediaType.includes("charset")
102
+ ) {
103
+ // See if text is encoded in UTF-8.
104
+ const text = toString(resource);
105
+ if (text !== null) {
106
+ // We were able to decode the TypedArray as UTF-8 text.
107
+ body = text;
108
+ mediaType += "; charset=utf-8";
109
+ }
99
110
  }
100
111
 
101
112
  // If we didn't get back some kind of data that response.write() accepts,
@@ -104,7 +115,7 @@ export default async function constructResponse(request, resource) {
104
115
  if (!validResponse) {
105
116
  const typeName = body?.constructor?.name ?? typeof body;
106
117
  console.error(
107
- `A served tree must return a string or a TypedArray but returned an instance of ${typeName}.`
118
+ `A served tree must return a string or a TypedArray but returned an instance of ${typeName}.`,
108
119
  );
109
120
  return null;
110
121
  }