mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Feat: implement HTTP 304 with SQLite Cache (#42)
This commit is contained in:
@@ -95,3 +95,30 @@ export function withBannerArray(title: string, description: string[] | readonly
|
||||
'################## EOF ##################'
|
||||
];
|
||||
};
|
||||
|
||||
export const mergeHeaders = (headersA: RequestInit['headers'] | undefined, headersB: RequestInit['headers']) => {
|
||||
if (headersA == null) {
|
||||
return headersB;
|
||||
}
|
||||
|
||||
if (Array.isArray(headersB)) {
|
||||
throw new TypeError('Array headers is not supported');
|
||||
}
|
||||
|
||||
const result = new Headers(headersA);
|
||||
|
||||
if (headersB instanceof Headers) {
|
||||
headersB.forEach((value, key) => {
|
||||
result.set(key, value);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
for (const key in headersB) {
|
||||
if (Object.hasOwn(headersB, key)) {
|
||||
result.set(key, (headersB as Record<string, string>)[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user