bosia 0.6.1 → 0.6.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/server.ts +17 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bosia",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "type": "module",
5
5
  "description": "A fast, batteries-included fullstack framework — SSR · Svelte 5 Runes · Bun · ElysiaJS. File-based routing inspired by SvelteKit. No Node.js, no Vite, no adapters.",
6
6
  "keywords": [
@@ -432,16 +432,31 @@ async function resolve(event: RequestEvent): Promise<Response> {
432
432
  cookies,
433
433
  });
434
434
 
435
+ const responseContentType = response.headers.get("content-type") ?? "";
436
+ // SSE responses are long-lived pub/sub streams — caching the buffered
437
+ // bytes would serve a stale finite snapshot to future subscribers and
438
+ // bypass the handler's subscribe() call entirely. Skip them.
439
+ const isEventStream = responseContentType.toLowerCase().includes("text/event-stream");
440
+
441
+ // Respect handler opt-out via Cache-Control. Standard HTTP semantics:
442
+ // no-store / private / no-cache all signal "don't reuse this response".
443
+ const cacheControl = (response.headers.get("cache-control") ?? "").toLowerCase();
444
+ const noStore =
445
+ cacheControl.includes("no-store") ||
446
+ cacheControl.includes("private") ||
447
+ cacheControl.includes("no-cache");
448
+
435
449
  if (
436
450
  apiCacheable &&
437
451
  apiCacheKey &&
438
452
  response.status === 200 &&
453
+ !isEventStream &&
454
+ !noStore &&
439
455
  (cookies as CookieJar).outgoing.length === 0
440
456
  ) {
441
457
  const cloned = response.clone();
442
458
  const extraHeaders = captureCacheableHeaders(response.headers);
443
- const contentType =
444
- response.headers.get("content-type") ?? "application/octet-stream";
459
+ const contentType = responseContentType || "application/octet-stream";
445
460
  const keyForWrite = apiCacheKey;
446
461
  queueMicrotask(async () => {
447
462
  try {