@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
|
@@ -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);
|
|
@@ -832,6 +830,10 @@ function createEventChunk(data, id) {
|
|
|
832
830
|
return CHUNK_ENCODER.encode(event + "\n");
|
|
833
831
|
}
|
|
834
832
|
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
833
|
+
function isEventStream(source) {
|
|
834
|
+
const contentType = source.headers.get("content-type");
|
|
835
|
+
return !!contentType && contentType.startsWith("text/event-stream");
|
|
836
|
+
}
|
|
835
837
|
function positionDigest(value) {
|
|
836
838
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
837
839
|
const text = JSON.stringify(value);
|
|
@@ -894,7 +896,7 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
894
896
|
if (!source.body) {
|
|
895
897
|
throw new Error("missing body");
|
|
896
898
|
}
|
|
897
|
-
const reader = new ChunkReader(source.body);
|
|
899
|
+
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
898
900
|
try {
|
|
899
901
|
const result = await reader.next();
|
|
900
902
|
if (!result.done) {
|
|
@@ -913,10 +915,18 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
913
915
|
}
|
|
914
916
|
const connection = wire && wire.connection;
|
|
915
917
|
let endConnection;
|
|
916
|
-
if (connection) ;
|
|
918
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
917
919
|
const end = error => {
|
|
918
920
|
const sweep = () => deserializeChunk.abort(error);
|
|
919
|
-
if (connection)
|
|
921
|
+
if (connection) {
|
|
922
|
+
const close = () => deserializeChunk.close();
|
|
923
|
+
endConnection({
|
|
924
|
+
open: deserializeChunk.open(),
|
|
925
|
+
error,
|
|
926
|
+
sweep,
|
|
927
|
+
close
|
|
928
|
+
});
|
|
929
|
+
} else sweep();
|
|
920
930
|
};
|
|
921
931
|
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
922
932
|
return interpretChunk(result.value);
|
|
@@ -926,9 +936,6 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
926
936
|
throw error;
|
|
927
937
|
}
|
|
928
938
|
}
|
|
929
|
-
async function deserializeString(text, codecOptions) {
|
|
930
|
-
return await deserializeStream(new Response(text), codecOptions);
|
|
931
|
-
}
|
|
932
939
|
async function decodeResponse(response, codecOptions) {
|
|
933
940
|
if (!response.body) return undefined;
|
|
934
941
|
return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
@@ -1238,6 +1245,57 @@ async function decodeFlashCookie(cookieHeader) {
|
|
|
1238
1245
|
}
|
|
1239
1246
|
}
|
|
1240
1247
|
|
|
1248
|
+
const RESPONSE_TAG = "seroval-plugins/web/Response";
|
|
1249
|
+
const REQUEST_TAG = "seroval-plugins/web/Request";
|
|
1250
|
+
const REFUSED_TAGS = [RESPONSE_TAG, REQUEST_TAG];
|
|
1251
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
1252
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
1253
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
1254
|
+
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.");
|
|
1255
|
+
error[REFUSED_ARGUMENT] = true;
|
|
1256
|
+
return error;
|
|
1257
|
+
}
|
|
1258
|
+
function refusedArgument(error) {
|
|
1259
|
+
for (let depth = 0; depth < 4 && error !== null && typeof error === "object"; depth++) {
|
|
1260
|
+
if (error[REFUSED_ARGUMENT] === true) return error;
|
|
1261
|
+
error = error.cause;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
const refused = plugin => REFUSED_TAGS.includes(plugin.tag);
|
|
1265
|
+
const reachesRefused = plugin => refused(plugin) || !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1266
|
+
function filterPlugins(plugins, out, seen) {
|
|
1267
|
+
for (const plugin of plugins) {
|
|
1268
|
+
if (seen.has(plugin)) continue;
|
|
1269
|
+
seen.add(plugin);
|
|
1270
|
+
if (refused(plugin)) continue;
|
|
1271
|
+
const severs = !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1272
|
+
out.push(severs ? {
|
|
1273
|
+
...plugin,
|
|
1274
|
+
extends: undefined
|
|
1275
|
+
} : plugin);
|
|
1276
|
+
if (plugin.extends) filterPlugins(plugin.extends, out, seen);
|
|
1277
|
+
}
|
|
1278
|
+
return out;
|
|
1279
|
+
}
|
|
1280
|
+
let defaultArgumentPlugins;
|
|
1281
|
+
const customArgumentPlugins = new WeakMap();
|
|
1282
|
+
function argumentDecodeCodec(codec, defaults) {
|
|
1283
|
+
const custom = codec && codec.plugins;
|
|
1284
|
+
let plugins = custom ? customArgumentPlugins.get(custom) : defaultArgumentPlugins;
|
|
1285
|
+
if (!plugins) {
|
|
1286
|
+
plugins = filterPlugins(custom ? [...custom, ...defaults] : defaults, [], new Set());
|
|
1287
|
+
if (custom) customArgumentPlugins.set(custom, plugins);else defaultArgumentPlugins = plugins;
|
|
1288
|
+
}
|
|
1289
|
+
return {
|
|
1290
|
+
...codec,
|
|
1291
|
+
[RESOLVED_PLUGINS]: plugins
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
function namesRefusedType(payload) {
|
|
1295
|
+
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1241
1299
|
const config = {
|
|
1242
1300
|
provideEvent: undefined,
|
|
1243
1301
|
wrapInvocation: undefined,
|
|
@@ -1595,20 +1653,28 @@ function createServerReference({
|
|
|
1595
1653
|
const scope = run => provideEvent(evt, run);
|
|
1596
1654
|
const wrap = resolveWrapInvocation(config.wrapInvocation);
|
|
1597
1655
|
const hook = requestErrorHook(ogEvt);
|
|
1598
|
-
let result
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1656
|
+
let result;
|
|
1657
|
+
try {
|
|
1658
|
+
result = provideEventOnce(provideEvent, evt, () => {
|
|
1659
|
+
const run = () => fn.apply(thisArg, args);
|
|
1660
|
+
return observeInvocation({
|
|
1661
|
+
id,
|
|
1662
|
+
direct: true,
|
|
1663
|
+
event: evt,
|
|
1664
|
+
args
|
|
1665
|
+
}, () => reportDirectFailure(() => wrap ? wrap(run, {
|
|
1666
|
+
id,
|
|
1667
|
+
args,
|
|
1668
|
+
event: evt,
|
|
1669
|
+
direct: true
|
|
1670
|
+
}) : run(), id, hook));
|
|
1671
|
+
});
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
throw directEnvelopeValue(error, evt);
|
|
1674
|
+
}
|
|
1675
|
+
result = result && typeof result.then === "function" ? result.then(value => directEnvelopeValue(value, evt), error => {
|
|
1676
|
+
throw directEnvelopeValue(error, evt);
|
|
1677
|
+
}) : directEnvelopeValue(result, evt);
|
|
1612
1678
|
result = scopeDeferredResult(result, scope);
|
|
1613
1679
|
const transform = config.transformDirectResult;
|
|
1614
1680
|
if (transform && result && typeof result.then === "function") {
|
|
@@ -1795,14 +1861,49 @@ function unknownFormatError(tag) {
|
|
|
1795
1861
|
error[FORMAT_SKEW] = true;
|
|
1796
1862
|
return error;
|
|
1797
1863
|
}
|
|
1798
|
-
async function
|
|
1864
|
+
async function decodeArguments(decode, payload) {
|
|
1865
|
+
if (payload === null) return await decode(undefined);
|
|
1866
|
+
const refuseNamed = () => {
|
|
1867
|
+
const text = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
|
|
1868
|
+
if (namesRefusedType(text)) throw refusedArgumentError();
|
|
1869
|
+
};
|
|
1870
|
+
const connection = {};
|
|
1871
|
+
let value;
|
|
1872
|
+
try {
|
|
1873
|
+
value = await decode({
|
|
1874
|
+
connection
|
|
1875
|
+
});
|
|
1876
|
+
} catch (error) {
|
|
1877
|
+
if (connection.ended) connection.ended.then(end => end.sweep());
|
|
1878
|
+
refuseNamed();
|
|
1879
|
+
throw error;
|
|
1880
|
+
}
|
|
1881
|
+
if (connection.ended) {
|
|
1882
|
+
const {
|
|
1883
|
+
open,
|
|
1884
|
+
sweep
|
|
1885
|
+
} = await connection.ended;
|
|
1886
|
+
sweep();
|
|
1887
|
+
if (open) refuseNamed();
|
|
1888
|
+
}
|
|
1889
|
+
return value;
|
|
1890
|
+
}
|
|
1891
|
+
let decodeModule;
|
|
1892
|
+
async function loadArgumentCodec(codec) {
|
|
1893
|
+
decodeModule = await import('@solidjs/web/serialization/decode');
|
|
1894
|
+
return argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS);
|
|
1895
|
+
}
|
|
1896
|
+
const argumentCodecFor = codec => decodeModule ? argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS) : loadArgumentCodec(codec);
|
|
1897
|
+
async function parseArguments(request, url, scripted, codec, buffered) {
|
|
1799
1898
|
const parsed = [];
|
|
1800
1899
|
const bodyFormat = request.method === "POST" ? request.headers.get(BODY_FORMAT_HEADER) : null;
|
|
1801
1900
|
const args = url.searchParams.get("args");
|
|
1802
1901
|
if (args && (!scripted || request.method === "GET" || bodyFormat !== BodyFormat.Serialized)) {
|
|
1803
1902
|
let result;
|
|
1804
1903
|
if (args.startsWith(";0x")) {
|
|
1805
|
-
|
|
1904
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1905
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1906
|
+
result = await decodeArguments(wire => deserializeStream(new Response(args), argumentCodec, wire), args);
|
|
1806
1907
|
} else {
|
|
1807
1908
|
result = JSON.parse(args);
|
|
1808
1909
|
assertDecodeDepth(result);
|
|
@@ -1822,7 +1923,14 @@ async function parseArguments(request, url, scripted, codec) {
|
|
|
1822
1923
|
throw unknownFormatError(bodyFormat);
|
|
1823
1924
|
}
|
|
1824
1925
|
const body = request.clone();
|
|
1825
|
-
|
|
1926
|
+
let decoded;
|
|
1927
|
+
if (bodyFormat === BodyFormat.Serialized) {
|
|
1928
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1929
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1930
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1931
|
+
} else {
|
|
1932
|
+
decoded = await extractBody(body, codec);
|
|
1933
|
+
}
|
|
1826
1934
|
if (bodyFormat === BodyFormat.Serialized || bodyFormat === BodyFormat.Json) {
|
|
1827
1935
|
if (bodyFormat === BodyFormat.Json) assertDecodeDepth(decoded);
|
|
1828
1936
|
if (!Array.isArray(decoded)) {
|
|
@@ -2492,7 +2600,7 @@ function encodeLiveResult(value, headers, status, codec, request, scope) {
|
|
|
2492
2600
|
function encodeResult(value, headers, status, codec, signal, scope) {
|
|
2493
2601
|
if (NULL_BODY_STATUSES.has(status)) {
|
|
2494
2602
|
if (value === undefined || value === null) {
|
|
2495
|
-
headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2603
|
+
if (status !== 304) headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2496
2604
|
return new Response(null, {
|
|
2497
2605
|
status,
|
|
2498
2606
|
headers
|
|
@@ -2579,6 +2687,7 @@ function currentEvent() {
|
|
|
2579
2687
|
}
|
|
2580
2688
|
function reportDirectFailure(run, id, hook) {
|
|
2581
2689
|
const report = error => {
|
|
2690
|
+
if (error instanceof Response || isResponseEnvelope(error)) throw error;
|
|
2582
2691
|
reportServerError(error, {
|
|
2583
2692
|
kind: "server-function",
|
|
2584
2693
|
handling: "thrown",
|
|
@@ -2595,6 +2704,20 @@ function reportDirectFailure(run, id, hook) {
|
|
|
2595
2704
|
}
|
|
2596
2705
|
return result && typeof result.then === "function" ? result.then(undefined, report) : result;
|
|
2597
2706
|
}
|
|
2707
|
+
function directEnvelopeValue(result, event) {
|
|
2708
|
+
if (!isResponseEnvelope(result)) return result;
|
|
2709
|
+
const {
|
|
2710
|
+
response,
|
|
2711
|
+
value
|
|
2712
|
+
} = result;
|
|
2713
|
+
const stub = event.response;
|
|
2714
|
+
if (response && stub && stub.headers && response.headers.getSetCookie) {
|
|
2715
|
+
for (const cookie of response.headers.getSetCookie()) {
|
|
2716
|
+
stub.headers.append("Set-Cookie", cookie);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
return value;
|
|
2720
|
+
}
|
|
2598
2721
|
function sanitizeServerError(value) {
|
|
2599
2722
|
if (DEV) return value;
|
|
2600
2723
|
if (isSafeError(value)) return value;
|
|
@@ -2799,6 +2922,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2799
2922
|
});
|
|
2800
2923
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2801
2924
|
}
|
|
2925
|
+
let argumentBytes = null;
|
|
2802
2926
|
if (method === "POST" && request.body !== null && bodySizeLimit !== Infinity) {
|
|
2803
2927
|
const raw = request.headers.get("content-length");
|
|
2804
2928
|
const declared = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
@@ -2824,6 +2948,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2824
2948
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2825
2949
|
}
|
|
2826
2950
|
request = withBufferedBody(request, buffered);
|
|
2951
|
+
argumentBytes = buffered;
|
|
2827
2952
|
}
|
|
2828
2953
|
let event;
|
|
2829
2954
|
try {
|
|
@@ -2843,8 +2968,14 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2843
2968
|
});
|
|
2844
2969
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2845
2970
|
}
|
|
2971
|
+
const commitResponse = raw => {
|
|
2972
|
+
if ((method === "GET" || method === "HEAD") && (sharedCacheMayStore(departingHeader(raw, event, "Cache-Control")) || cdnMayStore(departingHeader(raw, event, "CDN-Cache-Control")))) {
|
|
2973
|
+
withholdTrace(event);
|
|
2974
|
+
}
|
|
2975
|
+
return commitEventResponse(raw, event);
|
|
2976
|
+
};
|
|
2846
2977
|
const refuseCommitted = raw => {
|
|
2847
|
-
const response =
|
|
2978
|
+
const response = commitResponse(raw);
|
|
2848
2979
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2849
2980
|
};
|
|
2850
2981
|
const provide = options.provideEvent || provideEvent;
|
|
@@ -2874,10 +3005,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2874
3005
|
const collectsFlight = flightHooks.length > 0;
|
|
2875
3006
|
let parsed;
|
|
2876
3007
|
try {
|
|
2877
|
-
parsed = await parseArguments(request, url, scripted, codec);
|
|
3008
|
+
parsed = await parseArguments(request, url, scripted, codec, argumentBytes);
|
|
2878
3009
|
} catch (error) {
|
|
2879
|
-
const
|
|
2880
|
-
const response = new Response(DEV ?
|
|
3010
|
+
const named = error !== null && typeof error === "object" && error[FORMAT_SKEW] === true ? error : refusedArgument(error);
|
|
3011
|
+
const response = new Response(DEV ? named ? named.message : "Malformed server function arguments" : null, {
|
|
2881
3012
|
status: 400
|
|
2882
3013
|
});
|
|
2883
3014
|
return refuseCommitted(response);
|
|
@@ -2931,7 +3062,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2931
3062
|
response,
|
|
2932
3063
|
value
|
|
2933
3064
|
} = result;
|
|
2934
|
-
if (!scripted && !handleNoJS && response && response.body) {
|
|
3065
|
+
if (!scripted && !handleNoJS && response && response.body && isJSONSafe(value)) {
|
|
2935
3066
|
return response;
|
|
2936
3067
|
}
|
|
2937
3068
|
if (response && response.headers) {
|
|
@@ -3062,9 +3193,54 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3062
3193
|
return respondThrown(x);
|
|
3063
3194
|
}
|
|
3064
3195
|
};
|
|
3065
|
-
const response =
|
|
3196
|
+
const response = commitResponse(enforceComposedHeaderInvariants(ownResponse(await dispatch())));
|
|
3066
3197
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
3067
3198
|
}
|
|
3199
|
+
function departingHeader(response, event, name) {
|
|
3200
|
+
const own = response.headers.get(name);
|
|
3201
|
+
if (own !== null) return own;
|
|
3202
|
+
const stub = event.response;
|
|
3203
|
+
return stub && stub.headers && !stub.committed ? stub.headers.get(name) : null;
|
|
3204
|
+
}
|
|
3205
|
+
function cdnMayStore(cdnCacheControl) {
|
|
3206
|
+
return cdnCacheControl !== null && !forbidsStoring(cdnCacheControl);
|
|
3207
|
+
}
|
|
3208
|
+
function sharedCacheMayStore(cacheControl) {
|
|
3209
|
+
let shared = false;
|
|
3210
|
+
return !!cacheControl && !eachDirective(cacheControl, name => {
|
|
3211
|
+
if (name === "public" || name === "s-maxage") shared = true;
|
|
3212
|
+
}) && shared;
|
|
3213
|
+
}
|
|
3214
|
+
function forbidsStoring(value) {
|
|
3215
|
+
return eachDirective(value, () => {});
|
|
3216
|
+
}
|
|
3217
|
+
function eachDirective(value, visit) {
|
|
3218
|
+
let start = 0;
|
|
3219
|
+
let quoted = false;
|
|
3220
|
+
for (let i = 0; i <= value.length; i++) {
|
|
3221
|
+
const c = value[i];
|
|
3222
|
+
if (quoted) {
|
|
3223
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
3224
|
+
continue;
|
|
3225
|
+
}
|
|
3226
|
+
if (c === '"') {
|
|
3227
|
+
quoted = true;
|
|
3228
|
+
continue;
|
|
3229
|
+
}
|
|
3230
|
+
if (c !== "," && i < value.length) continue;
|
|
3231
|
+
const directive = value.slice(start, i);
|
|
3232
|
+
start = i + 1;
|
|
3233
|
+
const eq = directive.indexOf("=");
|
|
3234
|
+
const name = (eq === -1 ? directive : directive.slice(0, eq)).trim().toLowerCase();
|
|
3235
|
+
if (name === "no-store" || name === "private" && eq === -1) return true;
|
|
3236
|
+
visit(name);
|
|
3237
|
+
}
|
|
3238
|
+
return false;
|
|
3239
|
+
}
|
|
3240
|
+
function withholdTrace(event) {
|
|
3241
|
+
if (event.response && event.response.committed) return;
|
|
3242
|
+
traceForEvent(event).emit = false;
|
|
3243
|
+
}
|
|
3068
3244
|
function ownResponse(response) {
|
|
3069
3245
|
try {
|
|
3070
3246
|
return new Response(response.body, response);
|
|
@@ -3075,11 +3251,15 @@ function ownResponse(response) {
|
|
|
3075
3251
|
function finalizeTransportResponse(response, method) {
|
|
3076
3252
|
const stripBody = method === "HEAD" && response.body !== null;
|
|
3077
3253
|
const defaultsCache = !response.headers.has("Cache-Control") && response.status !== 304;
|
|
3078
|
-
|
|
3254
|
+
const defaultsSniff = !response.headers.has("X-Content-Type-Options");
|
|
3255
|
+
if (stripBody || defaultsCache || defaultsSniff) {
|
|
3079
3256
|
try {
|
|
3080
3257
|
if (defaultsCache) {
|
|
3081
3258
|
response.headers.set("Cache-Control", "no-store");
|
|
3082
3259
|
}
|
|
3260
|
+
if (defaultsSniff) {
|
|
3261
|
+
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
3262
|
+
}
|
|
3083
3263
|
if (!stripBody) return response;
|
|
3084
3264
|
response.body.cancel().catch(() => {});
|
|
3085
3265
|
return new Response(null, {
|
|
@@ -3090,6 +3270,9 @@ function finalizeTransportResponse(response, method) {
|
|
|
3090
3270
|
} catch {
|
|
3091
3271
|
const headers = new Headers(response.headers);
|
|
3092
3272
|
if (defaultsCache && !headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
|
|
3273
|
+
if (defaultsSniff && !headers.has("X-Content-Type-Options")) {
|
|
3274
|
+
headers.set("X-Content-Type-Options", "nosniff");
|
|
3275
|
+
}
|
|
3093
3276
|
if (stripBody) response.body.cancel().catch(() => {});
|
|
3094
3277
|
return new Response(stripBody ? null : response.body, {
|
|
3095
3278
|
status: response.status,
|