forked from nodejs/release-cloudflare-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.ts
39 lines (33 loc) · 921 Bytes
/
file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fileNotFound from '../responses/fileNotFound';
import { Context } from '../context';
import { getPrimaryProvider } from '../providers/providerFactory';
export async function getFile(
url: URL,
request: Request,
ctx: Context
): Promise<Response> {
const provider = getPrimaryProvider(ctx);
const result = await provider.getFile(request, url.pathname);
if (!result.exists) {
return fileNotFound(request);
}
return new Response(result.body, {
status: result.httpStatus,
headers: result.httpHeaders,
});
}
export async function headFile(
url: URL,
request: Request,
ctx: Context
): Promise<Response> {
const provider = getPrimaryProvider(ctx);
const result = await provider.head(request, url.pathname);
if (!result.exists) {
return fileNotFound(request);
}
return new Response(undefined, {
status: result.httpStatus,
headers: result.httpHeaders,
});
}