htmx-router 2.1.5 → 2.1.6
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/dist/index.d.ts +2 -1
- package/dist/response.js +19 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ParameterShaper } from "./util/parameters.js";
|
|
2
|
+
import type { GenericContext } from "./internal/router.js";
|
|
2
3
|
import type { RouteContext } from "./router.js";
|
|
3
4
|
export type RenderFunction<T extends ParameterShaper = {}> = (ctx: RouteContext<T>) => Promise<Response | JSX.Element | null>;
|
|
4
5
|
export type CatchFunction<T extends ParameterShaper = {}> = (ctx: RouteContext<T>, err: unknown) => Promise<Response | JSX.Element>;
|
|
@@ -15,4 +16,4 @@ export type ClientIslandManifest<T> = {
|
|
|
15
16
|
type ClientIsland<T> = T extends (props: infer P) => JSX.Element ? (props: P & {
|
|
16
17
|
children?: JSX.Element;
|
|
17
18
|
}) => JSX.Element : T;
|
|
18
|
-
export { RouteContext };
|
|
19
|
+
export { RouteContext, GenericContext };
|
package/dist/response.js
CHANGED
|
@@ -108,17 +108,29 @@ export function AssertETagStale(request, headers, etag, options) {
|
|
|
108
108
|
headers.append("Cache-Control", `max-age=${options.revalidate}`);
|
|
109
109
|
}
|
|
110
110
|
headers.append("Cache-Control", "must-revalidate");
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
etag = encodeURIComponent(etag.trim()); // safely handle any special characters
|
|
112
|
+
headers.set("ETag", `"${etag}"`);
|
|
113
|
+
const rules = request.headers.get("if-none-match");
|
|
114
|
+
if (!rules || !MatchEtags(rules.trim(), etag))
|
|
114
115
|
return;
|
|
115
|
-
const res = new Response(null, {
|
|
116
|
-
status: 304, statusText: "Not Modified",
|
|
117
|
-
headers
|
|
118
|
-
});
|
|
116
|
+
const res = new Response(null, { headers, status: 304, statusText: "Not Modified" });
|
|
119
117
|
res.headers.set("X-Caught", "true");
|
|
120
118
|
throw res;
|
|
121
119
|
}
|
|
120
|
+
function MatchEtags(header, etag) {
|
|
121
|
+
if (header === "*")
|
|
122
|
+
return true;
|
|
123
|
+
for (const term of header.split(/,\s*/)) {
|
|
124
|
+
let s = term.startsWith('W/') ? 'W/'.length : 0;
|
|
125
|
+
let e = term.endsWith('"') ? term.length - 1 : term.length;
|
|
126
|
+
if (term.startsWith('"', s))
|
|
127
|
+
s++;
|
|
128
|
+
const tag = term.slice(s, e);
|
|
129
|
+
if (etag === tag)
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
122
134
|
/**
|
|
123
135
|
* This is to fix issues with deno
|
|
124
136
|
* When you try and change the statusText on a Response object
|