@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
|
@@ -50,11 +50,9 @@ function parseTraceparent(value) {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
function randomHex(bytes) {
|
|
53
|
-
const buffer = new Uint8Array(bytes);
|
|
54
|
-
crypto.getRandomValues(buffer);
|
|
55
53
|
let out = "";
|
|
56
|
-
for (let i = 0; i <
|
|
57
|
-
return out;
|
|
54
|
+
for (let i = 0; i < bytes; i += 4) out += (Math.random() * 0x100000000 >>> 0).toString(16).padStart(8, "0");
|
|
55
|
+
return out.length === bytes * 2 ? out : out.slice(0, bytes * 2);
|
|
58
56
|
}
|
|
59
57
|
function randomTraceId() {
|
|
60
58
|
let id = randomHex(16);
|
|
@@ -802,6 +800,10 @@ function createEventChunk(data, id) {
|
|
|
802
800
|
return CHUNK_ENCODER.encode(event + "\n");
|
|
803
801
|
}
|
|
804
802
|
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
803
|
+
function isEventStream(source) {
|
|
804
|
+
const contentType = source.headers.get("content-type");
|
|
805
|
+
return !!contentType && contentType.startsWith("text/event-stream");
|
|
806
|
+
}
|
|
805
807
|
function positionDigest(value) {
|
|
806
808
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
807
809
|
const text = JSON.stringify(value);
|
|
@@ -864,7 +866,7 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
864
866
|
if (!source.body) {
|
|
865
867
|
throw new Error("missing body");
|
|
866
868
|
}
|
|
867
|
-
const reader = new ChunkReader(source.body);
|
|
869
|
+
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
868
870
|
try {
|
|
869
871
|
const result = await reader.next();
|
|
870
872
|
if (!result.done) {
|
|
@@ -883,10 +885,18 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
883
885
|
}
|
|
884
886
|
const connection = wire && wire.connection;
|
|
885
887
|
let endConnection;
|
|
886
|
-
if (connection) ;
|
|
888
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
887
889
|
const end = error => {
|
|
888
890
|
const sweep = () => deserializeChunk.abort(error);
|
|
889
|
-
if (connection)
|
|
891
|
+
if (connection) {
|
|
892
|
+
const close = () => deserializeChunk.close();
|
|
893
|
+
endConnection({
|
|
894
|
+
open: deserializeChunk.open(),
|
|
895
|
+
error,
|
|
896
|
+
sweep,
|
|
897
|
+
close
|
|
898
|
+
});
|
|
899
|
+
} else sweep();
|
|
890
900
|
};
|
|
891
901
|
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
892
902
|
return interpretChunk(result.value);
|
|
@@ -896,9 +906,6 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
896
906
|
throw error;
|
|
897
907
|
}
|
|
898
908
|
}
|
|
899
|
-
async function deserializeString(text, codecOptions) {
|
|
900
|
-
return await deserializeStream(new Response(text), codecOptions);
|
|
901
|
-
}
|
|
902
909
|
async function decodeResponse(response, codecOptions) {
|
|
903
910
|
if (!response.body) return undefined;
|
|
904
911
|
return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
@@ -1186,6 +1193,57 @@ async function decodeFlashCookie(cookieHeader) {
|
|
|
1186
1193
|
}
|
|
1187
1194
|
}
|
|
1188
1195
|
|
|
1196
|
+
const RESPONSE_TAG = "seroval-plugins/web/Response";
|
|
1197
|
+
const REQUEST_TAG = "seroval-plugins/web/Request";
|
|
1198
|
+
const REFUSED_TAGS = [RESPONSE_TAG, REQUEST_TAG];
|
|
1199
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
1200
|
+
const REFUSED_ARGUMENT = Symbol("solid.serverFunction.refusedArgument");
|
|
1201
|
+
function refusedArgumentError(name = "Response or Request") {
|
|
1202
|
+
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.");
|
|
1203
|
+
error[REFUSED_ARGUMENT] = true;
|
|
1204
|
+
return error;
|
|
1205
|
+
}
|
|
1206
|
+
function refusedArgument(error) {
|
|
1207
|
+
for (let depth = 0; depth < 4 && error !== null && typeof error === "object"; depth++) {
|
|
1208
|
+
if (error[REFUSED_ARGUMENT] === true) return error;
|
|
1209
|
+
error = error.cause;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const refused = plugin => REFUSED_TAGS.includes(plugin.tag);
|
|
1213
|
+
const reachesRefused = plugin => refused(plugin) || !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1214
|
+
function filterPlugins(plugins, out, seen) {
|
|
1215
|
+
for (const plugin of plugins) {
|
|
1216
|
+
if (seen.has(plugin)) continue;
|
|
1217
|
+
seen.add(plugin);
|
|
1218
|
+
if (refused(plugin)) continue;
|
|
1219
|
+
const severs = !!plugin.extends && plugin.extends.some(reachesRefused);
|
|
1220
|
+
out.push(severs ? {
|
|
1221
|
+
...plugin,
|
|
1222
|
+
extends: undefined
|
|
1223
|
+
} : plugin);
|
|
1224
|
+
if (plugin.extends) filterPlugins(plugin.extends, out, seen);
|
|
1225
|
+
}
|
|
1226
|
+
return out;
|
|
1227
|
+
}
|
|
1228
|
+
let defaultArgumentPlugins;
|
|
1229
|
+
const customArgumentPlugins = new WeakMap();
|
|
1230
|
+
function argumentDecodeCodec(codec, defaults) {
|
|
1231
|
+
const custom = codec && codec.plugins;
|
|
1232
|
+
let plugins = custom ? customArgumentPlugins.get(custom) : defaultArgumentPlugins;
|
|
1233
|
+
if (!plugins) {
|
|
1234
|
+
plugins = filterPlugins(custom ? [...custom, ...defaults] : defaults, [], new Set());
|
|
1235
|
+
if (custom) customArgumentPlugins.set(custom, plugins);else defaultArgumentPlugins = plugins;
|
|
1236
|
+
}
|
|
1237
|
+
return {
|
|
1238
|
+
...codec,
|
|
1239
|
+
[RESOLVED_PLUGINS]: plugins
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function namesRefusedType(payload) {
|
|
1243
|
+
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1189
1247
|
const config = {
|
|
1190
1248
|
provideEvent: undefined,
|
|
1191
1249
|
wrapInvocation: undefined,
|
|
@@ -1543,20 +1601,28 @@ function createServerReference({
|
|
|
1543
1601
|
const scope = run => provideEvent(evt, run);
|
|
1544
1602
|
const wrap = resolveWrapInvocation(config.wrapInvocation);
|
|
1545
1603
|
const hook = requestErrorHook(ogEvt);
|
|
1546
|
-
let result
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1604
|
+
let result;
|
|
1605
|
+
try {
|
|
1606
|
+
result = provideEventOnce(provideEvent, evt, () => {
|
|
1607
|
+
const run = () => fn.apply(thisArg, args);
|
|
1608
|
+
return observeInvocation({
|
|
1609
|
+
id,
|
|
1610
|
+
direct: true,
|
|
1611
|
+
event: evt,
|
|
1612
|
+
args
|
|
1613
|
+
}, () => reportDirectFailure(() => wrap ? wrap(run, {
|
|
1614
|
+
id,
|
|
1615
|
+
args,
|
|
1616
|
+
event: evt,
|
|
1617
|
+
direct: true
|
|
1618
|
+
}) : run(), id, hook));
|
|
1619
|
+
});
|
|
1620
|
+
} catch (error) {
|
|
1621
|
+
throw directEnvelopeValue(error, evt);
|
|
1622
|
+
}
|
|
1623
|
+
result = result && typeof result.then === "function" ? result.then(value => directEnvelopeValue(value, evt), error => {
|
|
1624
|
+
throw directEnvelopeValue(error, evt);
|
|
1625
|
+
}) : directEnvelopeValue(result, evt);
|
|
1560
1626
|
result = scopeDeferredResult(result, scope);
|
|
1561
1627
|
const transform = config.transformDirectResult;
|
|
1562
1628
|
if (transform && result && typeof result.then === "function") {
|
|
@@ -1743,14 +1809,49 @@ function unknownFormatError(tag) {
|
|
|
1743
1809
|
error[FORMAT_SKEW] = true;
|
|
1744
1810
|
return error;
|
|
1745
1811
|
}
|
|
1746
|
-
async function
|
|
1812
|
+
async function decodeArguments(decode, payload) {
|
|
1813
|
+
if (payload === null) return await decode(undefined);
|
|
1814
|
+
const refuseNamed = () => {
|
|
1815
|
+
const text = typeof payload === "string" ? payload : new TextDecoder().decode(payload);
|
|
1816
|
+
if (namesRefusedType(text)) throw refusedArgumentError();
|
|
1817
|
+
};
|
|
1818
|
+
const connection = {};
|
|
1819
|
+
let value;
|
|
1820
|
+
try {
|
|
1821
|
+
value = await decode({
|
|
1822
|
+
connection
|
|
1823
|
+
});
|
|
1824
|
+
} catch (error) {
|
|
1825
|
+
if (connection.ended) connection.ended.then(end => end.sweep());
|
|
1826
|
+
refuseNamed();
|
|
1827
|
+
throw error;
|
|
1828
|
+
}
|
|
1829
|
+
if (connection.ended) {
|
|
1830
|
+
const {
|
|
1831
|
+
open,
|
|
1832
|
+
sweep
|
|
1833
|
+
} = await connection.ended;
|
|
1834
|
+
sweep();
|
|
1835
|
+
if (open) refuseNamed();
|
|
1836
|
+
}
|
|
1837
|
+
return value;
|
|
1838
|
+
}
|
|
1839
|
+
let decodeModule;
|
|
1840
|
+
async function loadArgumentCodec(codec) {
|
|
1841
|
+
decodeModule = await import('@solidjs/web/serialization/decode');
|
|
1842
|
+
return argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS);
|
|
1843
|
+
}
|
|
1844
|
+
const argumentCodecFor = codec => decodeModule ? argumentDecodeCodec(codec, decodeModule.DEFAULT_WEB_PLUGINS) : loadArgumentCodec(codec);
|
|
1845
|
+
async function parseArguments(request, url, scripted, codec, buffered) {
|
|
1747
1846
|
const parsed = [];
|
|
1748
1847
|
const bodyFormat = request.method === "POST" ? request.headers.get(BODY_FORMAT_HEADER) : null;
|
|
1749
1848
|
const args = url.searchParams.get("args");
|
|
1750
1849
|
if (args && (!scripted || request.method === "GET" || bodyFormat !== BodyFormat.Serialized)) {
|
|
1751
1850
|
let result;
|
|
1752
1851
|
if (args.startsWith(";0x")) {
|
|
1753
|
-
|
|
1852
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1853
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1854
|
+
result = await decodeArguments(wire => deserializeStream(new Response(args), argumentCodec, wire), args);
|
|
1754
1855
|
} else {
|
|
1755
1856
|
result = JSON.parse(args);
|
|
1756
1857
|
assertDecodeDepth(result);
|
|
@@ -1770,7 +1871,14 @@ async function parseArguments(request, url, scripted, codec) {
|
|
|
1770
1871
|
throw unknownFormatError(bodyFormat);
|
|
1771
1872
|
}
|
|
1772
1873
|
const body = request.clone();
|
|
1773
|
-
|
|
1874
|
+
let decoded;
|
|
1875
|
+
if (bodyFormat === BodyFormat.Serialized) {
|
|
1876
|
+
let argumentCodec = argumentCodecFor(codec);
|
|
1877
|
+
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1878
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1879
|
+
} else {
|
|
1880
|
+
decoded = await extractBody(body, codec);
|
|
1881
|
+
}
|
|
1774
1882
|
if (bodyFormat === BodyFormat.Serialized || bodyFormat === BodyFormat.Json) {
|
|
1775
1883
|
if (bodyFormat === BodyFormat.Json) assertDecodeDepth(decoded);
|
|
1776
1884
|
if (!Array.isArray(decoded)) {
|
|
@@ -2440,7 +2548,7 @@ function encodeLiveResult(value, headers, status, codec, request, scope) {
|
|
|
2440
2548
|
function encodeResult(value, headers, status, codec, signal, scope) {
|
|
2441
2549
|
if (NULL_BODY_STATUSES.has(status)) {
|
|
2442
2550
|
if (value === undefined || value === null) {
|
|
2443
|
-
headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2551
|
+
if (status !== 304) headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
|
|
2444
2552
|
return new Response(null, {
|
|
2445
2553
|
status,
|
|
2446
2554
|
headers
|
|
@@ -2527,6 +2635,7 @@ function currentEvent() {
|
|
|
2527
2635
|
}
|
|
2528
2636
|
function reportDirectFailure(run, id, hook) {
|
|
2529
2637
|
const report = error => {
|
|
2638
|
+
if (error instanceof Response || isResponseEnvelope(error)) throw error;
|
|
2530
2639
|
reportServerError(error, {
|
|
2531
2640
|
kind: "server-function",
|
|
2532
2641
|
handling: "thrown",
|
|
@@ -2543,6 +2652,20 @@ function reportDirectFailure(run, id, hook) {
|
|
|
2543
2652
|
}
|
|
2544
2653
|
return result && typeof result.then === "function" ? result.then(undefined, report) : result;
|
|
2545
2654
|
}
|
|
2655
|
+
function directEnvelopeValue(result, event) {
|
|
2656
|
+
if (!isResponseEnvelope(result)) return result;
|
|
2657
|
+
const {
|
|
2658
|
+
response,
|
|
2659
|
+
value
|
|
2660
|
+
} = result;
|
|
2661
|
+
const stub = event.response;
|
|
2662
|
+
if (response && stub && stub.headers && response.headers.getSetCookie) {
|
|
2663
|
+
for (const cookie of response.headers.getSetCookie()) {
|
|
2664
|
+
stub.headers.append("Set-Cookie", cookie);
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
return value;
|
|
2668
|
+
}
|
|
2546
2669
|
function sanitizeServerError(value) {
|
|
2547
2670
|
if (DEV) return value;
|
|
2548
2671
|
if (isSafeError(value)) return value;
|
|
@@ -2736,6 +2859,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2736
2859
|
});
|
|
2737
2860
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2738
2861
|
}
|
|
2862
|
+
let argumentBytes = null;
|
|
2739
2863
|
if (method === "POST" && request.body !== null && bodySizeLimit !== Infinity) {
|
|
2740
2864
|
const raw = request.headers.get("content-length");
|
|
2741
2865
|
const declared = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
@@ -2761,6 +2885,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2761
2885
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2762
2886
|
}
|
|
2763
2887
|
request = withBufferedBody(request, buffered);
|
|
2888
|
+
argumentBytes = buffered;
|
|
2764
2889
|
}
|
|
2765
2890
|
let event;
|
|
2766
2891
|
try {
|
|
@@ -2780,8 +2905,14 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2780
2905
|
});
|
|
2781
2906
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2782
2907
|
}
|
|
2908
|
+
const commitResponse = raw => {
|
|
2909
|
+
if ((method === "GET" || method === "HEAD") && (sharedCacheMayStore(departingHeader(raw, event, "Cache-Control")) || cdnMayStore(departingHeader(raw, event, "CDN-Cache-Control")))) {
|
|
2910
|
+
withholdTrace(event);
|
|
2911
|
+
}
|
|
2912
|
+
return commitEventResponse(raw, event);
|
|
2913
|
+
};
|
|
2783
2914
|
const refuseCommitted = raw => {
|
|
2784
|
-
const response =
|
|
2915
|
+
const response = commitResponse(raw);
|
|
2785
2916
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2786
2917
|
};
|
|
2787
2918
|
const provide = options.provideEvent || provideEvent;
|
|
@@ -2811,10 +2942,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2811
2942
|
const collectsFlight = flightHooks.length > 0;
|
|
2812
2943
|
let parsed;
|
|
2813
2944
|
try {
|
|
2814
|
-
parsed = await parseArguments(request, url, scripted, codec);
|
|
2945
|
+
parsed = await parseArguments(request, url, scripted, codec, argumentBytes);
|
|
2815
2946
|
} catch (error) {
|
|
2816
|
-
const
|
|
2817
|
-
const response = new Response(DEV ?
|
|
2947
|
+
const named = error !== null && typeof error === "object" && error[FORMAT_SKEW] === true ? error : refusedArgument(error);
|
|
2948
|
+
const response = new Response(DEV ? named ? named.message : "Malformed server function arguments" : null, {
|
|
2818
2949
|
status: 400
|
|
2819
2950
|
});
|
|
2820
2951
|
return refuseCommitted(response);
|
|
@@ -2868,7 +2999,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2868
2999
|
response,
|
|
2869
3000
|
value
|
|
2870
3001
|
} = result;
|
|
2871
|
-
if (!scripted && !handleNoJS && response && response.body) {
|
|
3002
|
+
if (!scripted && !handleNoJS && response && response.body && isJSONSafe(value)) {
|
|
2872
3003
|
return response;
|
|
2873
3004
|
}
|
|
2874
3005
|
if (response && response.headers) {
|
|
@@ -2999,9 +3130,54 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2999
3130
|
return respondThrown(x);
|
|
3000
3131
|
}
|
|
3001
3132
|
};
|
|
3002
|
-
const response =
|
|
3133
|
+
const response = commitResponse(enforceComposedHeaderInvariants(ownResponse(await dispatch())));
|
|
3003
3134
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
3004
3135
|
}
|
|
3136
|
+
function departingHeader(response, event, name) {
|
|
3137
|
+
const own = response.headers.get(name);
|
|
3138
|
+
if (own !== null) return own;
|
|
3139
|
+
const stub = event.response;
|
|
3140
|
+
return stub && stub.headers && !stub.committed ? stub.headers.get(name) : null;
|
|
3141
|
+
}
|
|
3142
|
+
function cdnMayStore(cdnCacheControl) {
|
|
3143
|
+
return cdnCacheControl !== null && !forbidsStoring(cdnCacheControl);
|
|
3144
|
+
}
|
|
3145
|
+
function sharedCacheMayStore(cacheControl) {
|
|
3146
|
+
let shared = false;
|
|
3147
|
+
return !!cacheControl && !eachDirective(cacheControl, name => {
|
|
3148
|
+
if (name === "public" || name === "s-maxage") shared = true;
|
|
3149
|
+
}) && shared;
|
|
3150
|
+
}
|
|
3151
|
+
function forbidsStoring(value) {
|
|
3152
|
+
return eachDirective(value, () => {});
|
|
3153
|
+
}
|
|
3154
|
+
function eachDirective(value, visit) {
|
|
3155
|
+
let start = 0;
|
|
3156
|
+
let quoted = false;
|
|
3157
|
+
for (let i = 0; i <= value.length; i++) {
|
|
3158
|
+
const c = value[i];
|
|
3159
|
+
if (quoted) {
|
|
3160
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
3161
|
+
continue;
|
|
3162
|
+
}
|
|
3163
|
+
if (c === '"') {
|
|
3164
|
+
quoted = true;
|
|
3165
|
+
continue;
|
|
3166
|
+
}
|
|
3167
|
+
if (c !== "," && i < value.length) continue;
|
|
3168
|
+
const directive = value.slice(start, i);
|
|
3169
|
+
start = i + 1;
|
|
3170
|
+
const eq = directive.indexOf("=");
|
|
3171
|
+
const name = (eq === -1 ? directive : directive.slice(0, eq)).trim().toLowerCase();
|
|
3172
|
+
if (name === "no-store" || name === "private" && eq === -1) return true;
|
|
3173
|
+
visit(name);
|
|
3174
|
+
}
|
|
3175
|
+
return false;
|
|
3176
|
+
}
|
|
3177
|
+
function withholdTrace(event) {
|
|
3178
|
+
if (event.response && event.response.committed) return;
|
|
3179
|
+
traceForEvent(event).emit = false;
|
|
3180
|
+
}
|
|
3005
3181
|
function ownResponse(response) {
|
|
3006
3182
|
try {
|
|
3007
3183
|
return new Response(response.body, response);
|
|
@@ -3012,11 +3188,15 @@ function ownResponse(response) {
|
|
|
3012
3188
|
function finalizeTransportResponse(response, method) {
|
|
3013
3189
|
const stripBody = method === "HEAD" && response.body !== null;
|
|
3014
3190
|
const defaultsCache = !response.headers.has("Cache-Control") && response.status !== 304;
|
|
3015
|
-
|
|
3191
|
+
const defaultsSniff = !response.headers.has("X-Content-Type-Options");
|
|
3192
|
+
if (stripBody || defaultsCache || defaultsSniff) {
|
|
3016
3193
|
try {
|
|
3017
3194
|
if (defaultsCache) {
|
|
3018
3195
|
response.headers.set("Cache-Control", "no-store");
|
|
3019
3196
|
}
|
|
3197
|
+
if (defaultsSniff) {
|
|
3198
|
+
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
3199
|
+
}
|
|
3020
3200
|
if (!stripBody) return response;
|
|
3021
3201
|
response.body.cancel().catch(() => {});
|
|
3022
3202
|
return new Response(null, {
|
|
@@ -3027,6 +3207,9 @@ function finalizeTransportResponse(response, method) {
|
|
|
3027
3207
|
} catch {
|
|
3028
3208
|
const headers = new Headers(response.headers);
|
|
3029
3209
|
if (defaultsCache && !headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
|
|
3210
|
+
if (defaultsSniff && !headers.has("X-Content-Type-Options")) {
|
|
3211
|
+
headers.set("X-Content-Type-Options", "nosniff");
|
|
3212
|
+
}
|
|
3030
3213
|
if (stripBody) response.body.cancel().catch(() => {});
|
|
3031
3214
|
return new Response(stripBody ? null : response.body, {
|
|
3032
3215
|
status: response.status,
|