Skip to content

Commit e46e3e8

Browse files
committed
preserve cache header of origin
1 parent 6ee8549 commit e46e3e8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mod.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ const handler =
1515
cacheRoot: Deno.cwd(),
1616
}
1717
)
18+
19+
const originHeaders = await fetch(target).then(x => x.headers)
20+
21+
const cacheHeaders = Object.fromEntries(
22+
[
23+
"cache-control",
24+
"age",
25+
"expires",
26+
"etag",
27+
].map(header => [header, originHeaders.get(header)!])
28+
)
29+
1830
return new Response(
1931
result.get(target.href) || "",
2032
{
@@ -23,6 +35,7 @@ const handler =
2335
"content-type": "application/javascript",
2436
"access-control-allow-origin": "*",
2537
"x-typescript-types": target.href,
38+
...cacheHeaders,
2639
},
2740
}
2841
)

test/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<body>
77
Hello, World!
88
<script type="module">
9-
import { $ } from "http://tsm.deno.dev/https://deno.land/x/[email protected]/mod.ts"
9+
import { $ } from "http://localhost:8081/https://deno.land/x/[email protected]/mod.ts"
1010
$([1, 2, 3, 4, 5])
1111
.filter(x => x % 2 === 0)
1212
.map(x => x * 2)

0 commit comments

Comments
 (0)