@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.16
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/README.md +1 -1
- package/dist/server.dev.js +475 -591
- package/dist/server.js +459 -489
- package/dist/server.observe.js +459 -498
- package/dist/web.dev.js +206 -220
- package/dist/web.js +196 -208
- package/dist/web.observe.js +206 -213
- package/frames/dist/client.dev.js +664 -643
- package/frames/dist/client.js +593 -582
- package/frames/dist/client.observe.js +624 -589
- package/frames/dist/regions.js +43 -2
- package/frames/dist/server.dev.js +578 -450
- package/frames/dist/server.js +578 -397
- package/frames/dist/server.observe.js +578 -397
- package/frames/dist/trace.js +4 -1
- package/frames/dist/wire.js +371 -6
- package/package.json +13 -13
- package/serialization/dist/decode.js +11 -9
- package/serialization/dist/serialization.js +11 -9
- package/serialization/types/serializer-decode.d.ts +2 -2
- package/server-functions/dist/client.dev.js +5 -2
- package/server-functions/dist/client.js +3 -2
- package/server-functions/dist/client.observe.js +5 -2
- package/server-functions/dist/rich-args.js +33 -1
- package/server-functions/dist/server.dev.js +218 -35
- package/server-functions/dist/server.js +218 -35
- package/server-functions/dist/server.observe.js +218 -35
- package/skills/server-components/SKILL.md +74 -185
- package/types/client.d.ts +112 -10
- package/types/constants.d.ts +2 -1
- package/types/frames/assets-tier.d.ts +2 -2
- package/types/frames/client.d.ts +8 -3
- package/types/frames/frame-client.d.ts +121 -157
- package/types/frames/frame-morph.d.ts +28 -0
- package/types/frames/frame-sink.d.ts +13 -9
- package/types/frames/frame-transport.d.ts +30 -1
- package/types/frames/regions-tier.d.ts +15 -0
- package/types/frames/serializer-decode.d.ts +2 -2
- package/types/frames/server.d.ts +1 -53
- package/types/frames/wire-tier.d.ts +54 -1
- package/types/head.d.ts +1 -0
- package/types/index.d.ts +57 -50
- package/types/index.server.d.ts +3 -27
- package/types/jsx.d.ts +14 -17
- package/types/observe.d.ts +14 -7
- package/types/render.d.ts +3 -1
- package/types/response.d.ts +31 -8
- package/types/serializer-decode.d.ts +2 -2
- package/types/server-functions/argument-codec.d.ts +21 -0
- package/types/server-functions/client.d.ts +18 -5
- package/types/server-functions/server.d.ts +6 -2
- package/types/server-functions/shared.d.ts +19 -0
- package/types/server-mock.d.ts +9 -2
- package/types/server-observe.d.ts +3 -2
- package/types/server.d.ts +124 -67
- package/frames/dist/bind.dev.js +0 -326
- package/frames/dist/bind.js +0 -295
- package/types/frames/bind-tier.d.ts +0 -60
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
import { configureServerFunctionsClient, serializeString, getServerFunctionsCodec } from '@solidjs/web/server-functions/client';
|
|
2
2
|
|
|
3
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
4
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
5
|
+
const error = new TypeError(`Server function arguments cannot carry Response or Request values (got a ${name}). ` + "Pass the data it holds — its body, headers or url — instead.");
|
|
6
|
+
error[REFUSED_ARGUMENT] = true;
|
|
7
|
+
return error;
|
|
8
|
+
}
|
|
9
|
+
function encodeRefusal(name) {
|
|
10
|
+
const refuse = () => {
|
|
11
|
+
throw refusedArgumentError(name);
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
tag: `seroval-plugins/web/${name}`,
|
|
15
|
+
test: value => typeof globalThis[name] === "function" && value instanceof globalThis[name],
|
|
16
|
+
parse: {
|
|
17
|
+
sync: refuse,
|
|
18
|
+
async: refuse,
|
|
19
|
+
stream: refuse
|
|
20
|
+
},
|
|
21
|
+
serialize: refuse,
|
|
22
|
+
deserialize: refuse
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let encodeRefusals;
|
|
26
|
+
function argumentEncodeCodec(codec) {
|
|
27
|
+
if (!encodeRefusals) encodeRefusals = [encodeRefusal("Response"), encodeRefusal("Request")];
|
|
28
|
+
const refusals = encodeRefusals;
|
|
29
|
+
return {
|
|
30
|
+
...codec,
|
|
31
|
+
plugins: codec && codec.plugins ? [...refusals, ...codec.plugins] : refusals
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
3
35
|
function enableRichArguments() {
|
|
4
36
|
configureServerFunctionsClient({
|
|
5
|
-
serializeArgs: args => serializeString(args, getServerFunctionsCodec())
|
|
37
|
+
serializeArgs: args => serializeString(args, argumentEncodeCodec(getServerFunctionsCodec()))
|
|
6
38
|
});
|
|
7
39
|
}
|
|
8
40
|
|
|
@@ -56,11 +56,9 @@ function parseTraceparent(value) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
function randomHex(bytes) {
|
|
59
|
-
const buffer = new Uint8Array(bytes);
|
|
60
|
-
crypto.getRandomValues(buffer);
|
|
61
59
|
let out = "";
|
|
62
|
-
for (let i = 0; i <
|
|
63
|
-
return out;
|
|
60
|
+
for (let i = 0; i < bytes; i += 4) out += (Math.random() * 0x100000000 >>> 0).toString(16).padStart(8, "0");
|
|
61
|
+
return out.length === bytes * 2 ? out : out.slice(0, bytes * 2);
|
|
64
62
|
}
|
|
65
63
|
function randomTraceId() {
|
|
66
64
|
let id = randomHex(16);
|
|
@@ -853,6 +851,10 @@ function createEventChunk(data, id) {
|
|
|
853
851
|
return CHUNK_ENCODER.encode(event + "\n");
|
|
854
852
|
}
|
|
855
853
|
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
854
|
+
function isEventStream(source) {
|
|
855
|
+
const contentType = source.headers.get("content-type");
|
|
856
|
+
return !!contentType && contentType.startsWith("text/event-stream");
|
|
857
|
+
}
|
|
856
858
|
function positionDigest(value) {
|
|
857
859
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
858
860
|
const text = JSON.stringify(value);
|
|
@@ -915,7 +917,7 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
915
917
|
if (!source.body) {
|
|
916
918
|
throw new Error("missing body");
|
|
917
919
|
}
|
|
918
|
-
const reader = new ChunkReader(source.body);
|
|
920
|
+
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
919
921
|
try {
|
|
920
922
|
const result = await reader.next();
|
|
921
923
|
if (!result.done) {
|
|
@@ -934,10 +936,18 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
934
936
|
}
|
|
935
937
|
const connection = wire && wire.connection;
|
|
936
938
|
let endConnection;
|
|
937
|
-
if (connection) ;
|
|
939
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
938
940
|
const end = error => {
|
|
939
941
|
const sweep = () => deserializeChunk.abort(error);
|
|
940
|
-
if (connection)
|
|
942
|
+
if (connection) {
|
|
943
|
+
const close = () => deserializeChunk.close();
|
|
944
|
+
endConnection({
|
|
945
|
+
open: deserializeChunk.open(),
|
|
946
|
+
error,
|
|
947
|
+
sweep,
|
|
948
|
+
close
|
|
949
|
+
});
|
|
950
|
+
} else sweep();
|
|
941
951
|
};
|
|
942
952
|
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
943
953
|
return interpretChunk(result.value);
|
|
@@ -947,9 +957,6 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
947
957
|
throw error;
|
|
948
958
|
}
|
|
949
959
|
}
|
|
950
|
-
async function deserializeString(text, codecOptions) {
|
|
951
|
-
return await deserializeStream(new Response(text), codecOptions);
|
|
952
|
-
}
|
|
953
960
|
async function decodeResponse(response, codecOptions) {
|
|
954
961
|
if (!response.body) return undefined;
|
|
955
962
|
return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
@@ -1268,6 +1275,57 @@ async function decodeFlashCookie(cookieHeader) {
|
|
|
1268
1275
|
}
|
|
1269
1276
|
}
|
|
1270
1277
|
|
|
1278
|
+
const RESPONSE_TAG = "seroval-plugins/web/Response";
|
|
1279
|
+
const REQUEST_TAG = "seroval-plugins/web/Request";
|
|
1280
|
+
const REFUSED_TAGS = [RESPONSE_TAG, REQUEST_TAG];
|
|
1281
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
1282
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
1283
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
1284
|
+
const error = new TypeError(`Server function arguments cannot carry Response or Request values (got a ${name}). ` + "Pass the data it holds — its body, headers or url — instead.");
|
|
1285
|
+
error[REFUSED_ARGUMENT] = true;
|
|
1286
|
+
return error;
|
|
1287
|
+
}
|
|
1288
|
+
function refusedArgument(error) {
|
|
1289
|
+
for (let depth = 0; depth < 4 && error !== null && typeof error === "object"; depth++) {
|
|
1290
|
+
if (error[REFUSED_ARGUMENT] === true) return error;
|
|
1291
|
+
error = error.cause;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
const refused = plugin => REFUSED_TAGS.includes(plugin.tag);
|
|
1295
|
+
const reachesRefused = plugin => refused(plugin) || !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1296
|
+
function filterPlugins(plugins, out, seen) {
|
|
1297
|
+
for (const plugin of plugins) {
|
|
1298
|
+
if (seen.has(plugin)) continue;
|
|
1299
|
+
seen.add(plugin);
|
|
1300
|
+
if (refused(plugin)) continue;
|
|
1301
|
+
const severs = !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1302
|
+
out.push(severs ? {
|
|
1303
|
+
...plugin,
|
|
1304
|
+
extends: undefined
|
|
1305
|
+
} : plugin);
|
|
1306
|
+
if (plugin.extends) filterPlugins(plugin.extends, out, seen);
|
|
1307
|
+
}
|
|
1308
|
+
return out;
|
|
1309
|
+
}
|
|
1310
|
+
let defaultArgumentPlugins;
|
|
1311
|
+
const customArgumentPlugins = new WeakMap();
|
|
1312
|
+
function argumentDecodeCodec(codec, defaults) {
|
|
1313
|
+
const custom = codec && codec.plugins;
|
|
1314
|
+
let plugins = custom ? customArgumentPlugins.get(custom) : defaultArgumentPlugins;
|
|
1315
|
+
if (!plugins) {
|
|
1316
|
+
plugins = filterPlugins(custom ? [...custom, ...defaults] : defaults, [], new Set());
|
|
1317
|
+
if (custom) customArgumentPlugins.set(custom, plugins);else defaultArgumentPlugins = plugins;
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
...codec,
|
|
1321
|
+
[RESOLVED_PLUGINS]: plugins
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function namesRefusedType(payload) {
|
|
1325
|
+
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1271
1329
|
const config = {
|
|
1272
1330
|
provideEvent: undefined,
|
|
1273
1331
|
wrapInvocation: undefined,
|
|
@@ -1625,20 +1683,28 @@ function createServerReference({
|
|
|
1625
1683
|
const scope = run => provideEvent(evt, run);
|
|
1626
1684
|
const wrap = resolveWrapInvocation(config.wrapInvocation);
|
|
1627
1685
|
const hook = requestErrorHook(ogEvt);
|
|
1628
|
-
let result
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1686
|
+
let result;
|
|
1687
|
+
try {
|
|
1688
|
+
result = provideEventOnce(provideEvent, evt, () => {
|
|
1689
|
+
const run = () => fn.apply(thisArg, args);
|
|
1690
|
+
return observeInvocation({
|
|
1691
|
+
id,
|
|
1692
|
+
direct: true,
|
|
1693
|
+
event: evt,
|
|
1694
|
+
args
|
|
1695
|
+
}, () => reportDirectFailure(() => wrap ? wrap(run, {
|
|
1696
|
+
id,
|
|
1697
|
+
args,
|
|
1698
|
+
event: evt,
|
|
1699
|
+
direct: true
|
|
1700
|
+
}) : run(), id, hook));
|
|
1701
|
+
});
|
|
1702
|
+
} catch (error) {
|
|
1703
|
+
throw directEnvelopeValue(error, evt);
|
|
1704
|
+
}
|
|
1705
|
+
result = result && typeof result.then === "function" ? result.then(value => directEnvelopeValue(value, evt), error => {
|
|
1706
|
+
throw directEnvelopeValue(error, evt);
|
|
1707
|
+
}) : directEnvelopeValue(result, evt);
|
|
1642
1708
|
result = scopeDeferredResult(result, scope);
|
|
1643
1709
|
const transform = config.transformDirectResult;
|
|
1644
1710
|
if (transform && result && typeof result.then === "function") {
|
|
@@ -1825,14 +1891,49 @@ function unknownFormatError(tag) {
|
|
|
1825
1891
|
error[FORMAT_SKEW] = true;
|
|
1826
1892
|
return error;
|
|
1827
1893
|
}
|
|
1828
|
-
async function
|
|
1894
|
+
async function decodeArguments(decode, payload) {
|
|
1895
|
+
if (payload === null) return await decode(undefined);
|
|
1896
|
+
const refuseNamed = () => {
|
|
1897
|
+
const text = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
|
|
1898
|
+
if (namesRefusedType(text)) throw refusedArgumentError();
|
|
1899
|
+
};
|
|
1900
|
+
const connection = {};
|
|
1901
|
+
let value;
|
|
1902
|
+
try {
|
|
1903
|
+
value = await decode({
|
|
1904
|
+
connection
|
|
1905
|
+
});
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
if (connection.ended) connection.ended.then(end => end.sweep());
|
|
1908
|
+
refuseNamed();
|
|
1909
|
+
throw error;
|
|
1910
|
+
}
|
|
1911
|
+
if (connection.ended) {
|
|
1912
|
+
const {
|
|
1913
|
+
open,
|
|
1914
|
+
sweep
|
|
1915
|
+
} = await connection.ended;
|
|
1916
|
+
sweep();
|
|
1917
|
+
if (open) refuseNamed();
|
|
1918
|
+
}
|
|
1919
|
+
return value;
|
|
1920
|
+
}
|
|
1921
|
+
let decodeModule;
|
|
1922
|
+
async function loadArgumentCodec(codec) {
|
|
1923
|
+
decodeModule = await import('@solidjs/web/serialization/decode');
|
|
1924
|
+
return argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS);
|
|
1925
|
+
}
|
|
1926
|
+
const argumentCodecFor = codec => decodeModule ? argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS) : loadArgumentCodec(codec);
|
|
1927
|
+
async function parseArguments(request, url, scripted, codec, buffered) {
|
|
1829
1928
|
const parsed = [];
|
|
1830
1929
|
const bodyFormat = request.method === "POST" ? request.headers.get(BODY_FORMAT_HEADER) : null;
|
|
1831
1930
|
const args = url.searchParams.get("args");
|
|
1832
1931
|
if (args && (!scripted || request.method === "GET" || bodyFormat !== BodyFormat.Serialized)) {
|
|
1833
1932
|
let result;
|
|
1834
1933
|
if (args.startsWith(";0x")) {
|
|
1835
|
-
|
|
1934
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1935
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1936
|
+
result = await decodeArguments(wire => deserializeStream(new Response(args), argumentCodec, wire), args);
|
|
1836
1937
|
} else {
|
|
1837
1938
|
result = JSON.parse(args);
|
|
1838
1939
|
assertDecodeDepth(result);
|
|
@@ -1852,7 +1953,14 @@ async function parseArguments(request, url, scripted, codec) {
|
|
|
1852
1953
|
throw unknownFormatError(bodyFormat);
|
|
1853
1954
|
}
|
|
1854
1955
|
const body = request.clone();
|
|
1855
|
-
|
|
1956
|
+
let decoded;
|
|
1957
|
+
if (bodyFormat === BodyFormat.Serialized) {
|
|
1958
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1959
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1960
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1961
|
+
} else {
|
|
1962
|
+
decoded = await extractBody(body, codec);
|
|
1963
|
+
}
|
|
1856
1964
|
if (bodyFormat === BodyFormat.Serialized || bodyFormat === BodyFormat.Json) {
|
|
1857
1965
|
if (bodyFormat === BodyFormat.Json) assertDecodeDepth(decoded);
|
|
1858
1966
|
if (!Array.isArray(decoded)) {
|
|
@@ -2522,7 +2630,7 @@ function encodeLiveResult(value, headers, status, codec, request, scope) {
|
|
|
2522
2630
|
function encodeResult(value, headers, status, codec, signal, scope) {
|
|
2523
2631
|
if (NULL_BODY_STATUSES.has(status)) {
|
|
2524
2632
|
if (value === undefined || value === null) {
|
|
2525
|
-
headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2633
|
+
if (status !== 304) headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2526
2634
|
return new Response(null, {
|
|
2527
2635
|
status,
|
|
2528
2636
|
headers
|
|
@@ -2609,6 +2717,7 @@ function currentEvent() {
|
|
|
2609
2717
|
}
|
|
2610
2718
|
function reportDirectFailure(run, id, hook) {
|
|
2611
2719
|
const report = error => {
|
|
2720
|
+
if (error instanceof Response || isResponseEnvelope(error)) throw error;
|
|
2612
2721
|
reportServerError(error, {
|
|
2613
2722
|
kind: "server-function",
|
|
2614
2723
|
handling: "thrown",
|
|
@@ -2625,6 +2734,20 @@ function reportDirectFailure(run, id, hook) {
|
|
|
2625
2734
|
}
|
|
2626
2735
|
return result && typeof result.then === "function" ? result.then(undefined, report) : result;
|
|
2627
2736
|
}
|
|
2737
|
+
function directEnvelopeValue(result, event) {
|
|
2738
|
+
if (!isResponseEnvelope(result)) return result;
|
|
2739
|
+
const {
|
|
2740
|
+
response,
|
|
2741
|
+
value
|
|
2742
|
+
} = result;
|
|
2743
|
+
const stub = event.response;
|
|
2744
|
+
if (response && stub && stub.headers && response.headers.getSetCookie) {
|
|
2745
|
+
for (const cookie of response.headers.getSetCookie()) {
|
|
2746
|
+
stub.headers.append("Set-Cookie", cookie);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
return value;
|
|
2750
|
+
}
|
|
2628
2751
|
function sanitizeServerError(value) {
|
|
2629
2752
|
if (DEV) return value;
|
|
2630
2753
|
if (isSafeError(value)) return value;
|
|
@@ -2829,6 +2952,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2829
2952
|
});
|
|
2830
2953
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2831
2954
|
}
|
|
2955
|
+
let argumentBytes = null;
|
|
2832
2956
|
if (method === "POST" && request.body !== null && bodySizeLimit !== Infinity) {
|
|
2833
2957
|
const raw = request.headers.get("content-length");
|
|
2834
2958
|
const declared = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
@@ -2854,6 +2978,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2854
2978
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2855
2979
|
}
|
|
2856
2980
|
request = withBufferedBody(request, buffered);
|
|
2981
|
+
argumentBytes = buffered;
|
|
2857
2982
|
}
|
|
2858
2983
|
let event;
|
|
2859
2984
|
try {
|
|
@@ -2873,8 +2998,14 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2873
2998
|
});
|
|
2874
2999
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2875
3000
|
}
|
|
3001
|
+
const commitResponse = raw => {
|
|
3002
|
+
if ((method === "GET" || method === "HEAD") && (sharedCacheMayStore(departingHeader(raw, event, "Cache-Control")) || cdnMayStore(departingHeader(raw, event, "CDN-Cache-Control")))) {
|
|
3003
|
+
withholdTrace(event);
|
|
3004
|
+
}
|
|
3005
|
+
return commitEventResponse(raw, event);
|
|
3006
|
+
};
|
|
2876
3007
|
const refuseCommitted = raw => {
|
|
2877
|
-
const response =
|
|
3008
|
+
const response = commitResponse(raw);
|
|
2878
3009
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2879
3010
|
};
|
|
2880
3011
|
const provide = options.provideEvent || provideEvent;
|
|
@@ -2904,10 +3035,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2904
3035
|
const collectsFlight = flightHooks.length > 0;
|
|
2905
3036
|
let parsed;
|
|
2906
3037
|
try {
|
|
2907
|
-
parsed = await parseArguments(request, url, scripted, codec);
|
|
3038
|
+
parsed = await parseArguments(request, url, scripted, codec, argumentBytes);
|
|
2908
3039
|
} catch (error) {
|
|
2909
|
-
const
|
|
2910
|
-
const response = new Response(DEV ?
|
|
3040
|
+
const named = error !== null && typeof error === "object" && error[FORMAT_SKEW] === true ? error : refusedArgument(error);
|
|
3041
|
+
const response = new Response(DEV ? named ? named.message : "Malformed server function arguments" : null, {
|
|
2911
3042
|
status: 400
|
|
2912
3043
|
});
|
|
2913
3044
|
return refuseCommitted(response);
|
|
@@ -2961,7 +3092,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2961
3092
|
response,
|
|
2962
3093
|
value
|
|
2963
3094
|
} = result;
|
|
2964
|
-
if (!scripted && !handleNoJS && response && response.body) {
|
|
3095
|
+
if (!scripted && !handleNoJS && response && response.body && isJSONSafe(value)) {
|
|
2965
3096
|
return response;
|
|
2966
3097
|
}
|
|
2967
3098
|
if (response && response.headers) {
|
|
@@ -3092,9 +3223,54 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3092
3223
|
return respondThrown(x);
|
|
3093
3224
|
}
|
|
3094
3225
|
};
|
|
3095
|
-
const response =
|
|
3226
|
+
const response = commitResponse(enforceComposedHeaderInvariants(ownResponse(await dispatch())));
|
|
3096
3227
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
3097
3228
|
}
|
|
3229
|
+
function departingHeader(response, event, name) {
|
|
3230
|
+
const own = response.headers.get(name);
|
|
3231
|
+
if (own !== null) return own;
|
|
3232
|
+
const stub = event.response;
|
|
3233
|
+
return stub && stub.headers && !stub.committed ? stub.headers.get(name) : null;
|
|
3234
|
+
}
|
|
3235
|
+
function cdnMayStore(cdnCacheControl) {
|
|
3236
|
+
return cdnCacheControl !== null && !forbidsStoring(cdnCacheControl);
|
|
3237
|
+
}
|
|
3238
|
+
function sharedCacheMayStore(cacheControl) {
|
|
3239
|
+
let shared = false;
|
|
3240
|
+
return !!cacheControl && !eachDirective(cacheControl, name => {
|
|
3241
|
+
if (name === "public" || name === "s-maxage") shared = true;
|
|
3242
|
+
}) && shared;
|
|
3243
|
+
}
|
|
3244
|
+
function forbidsStoring(value) {
|
|
3245
|
+
return eachDirective(value, () => {});
|
|
3246
|
+
}
|
|
3247
|
+
function eachDirective(value, visit) {
|
|
3248
|
+
let start = 0;
|
|
3249
|
+
let quoted = false;
|
|
3250
|
+
for (let i = 0; i <= value.length; i++) {
|
|
3251
|
+
const c = value[i];
|
|
3252
|
+
if (quoted) {
|
|
3253
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
if (c === '"') {
|
|
3257
|
+
quoted = true;
|
|
3258
|
+
continue;
|
|
3259
|
+
}
|
|
3260
|
+
if (c !== "," && i < value.length) continue;
|
|
3261
|
+
const directive = value.slice(start, i);
|
|
3262
|
+
start = i + 1;
|
|
3263
|
+
const eq = directive.indexOf("=");
|
|
3264
|
+
const name = (eq === -1 ? directive : directive.slice(0, eq)).trim().toLowerCase();
|
|
3265
|
+
if (name === "no-store" || name === "private" && eq === -1) return true;
|
|
3266
|
+
visit(name);
|
|
3267
|
+
}
|
|
3268
|
+
return false;
|
|
3269
|
+
}
|
|
3270
|
+
function withholdTrace(event) {
|
|
3271
|
+
if (event.response && event.response.committed) return;
|
|
3272
|
+
traceForEvent(event).emit = false;
|
|
3273
|
+
}
|
|
3098
3274
|
function ownResponse(response) {
|
|
3099
3275
|
try {
|
|
3100
3276
|
return new Response(response.body, response);
|
|
@@ -3105,11 +3281,15 @@ function ownResponse(response) {
|
|
|
3105
3281
|
function finalizeTransportResponse(response, method) {
|
|
3106
3282
|
const stripBody = method === "HEAD" && response.body !== null;
|
|
3107
3283
|
const defaultsCache = !response.headers.has("Cache-Control") && response.status !== 304;
|
|
3108
|
-
|
|
3284
|
+
const defaultsSniff = !response.headers.has("X-Content-Type-Options");
|
|
3285
|
+
if (stripBody || defaultsCache || defaultsSniff) {
|
|
3109
3286
|
try {
|
|
3110
3287
|
if (defaultsCache) {
|
|
3111
3288
|
response.headers.set("Cache-Control", "no-store");
|
|
3112
3289
|
}
|
|
3290
|
+
if (defaultsSniff) {
|
|
3291
|
+
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
3292
|
+
}
|
|
3113
3293
|
if (!stripBody) return response;
|
|
3114
3294
|
response.body.cancel().catch(() => {});
|
|
3115
3295
|
return new Response(null, {
|
|
@@ -3120,6 +3300,9 @@ function finalizeTransportResponse(response, method) {
|
|
|
3120
3300
|
} catch {
|
|
3121
3301
|
const headers = new Headers(response.headers);
|
|
3122
3302
|
if (defaultsCache && !headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
|
|
3303
|
+
if (defaultsSniff && !headers.has("X-Content-Type-Options")) {
|
|
3304
|
+
headers.set("X-Content-Type-Options", "nosniff");
|
|
3305
|
+
}
|
|
3123
3306
|
if (stripBody) response.body.cancel().catch(() => {});
|
|
3124
3307
|
return new Response(stripBody ? null : response.body, {
|
|
3125
3308
|
status: response.status,
|