1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const mime = require("mime-types");
|
4 | const url_1 = require("url");
|
5 | const getContentType = (pathname) => {
|
6 | const mimeType = mime.lookup(pathname);
|
7 | return (mimeType && mime.contentType(mimeType)) || 'text/html; charset=utf-8';
|
8 | };
|
9 | const excludedHeaders = new Set([
|
10 | 'cache-control',
|
11 | 'connection',
|
12 | 'content-encoding',
|
13 | 'content-length',
|
14 | 'expect',
|
15 | 'keep-alive',
|
16 | 'proxy-authenticate',
|
17 | 'proxy-authorization',
|
18 | 'proxy-connection',
|
19 | 'trailer',
|
20 | 'upgrade',
|
21 | 'x-accel-buffering',
|
22 | 'x-accel-charset',
|
23 | 'x-accel-limit-rate',
|
24 | 'x-accel-redirect',
|
25 | 'x-cache',
|
26 | 'x-forwarded-proto',
|
27 | 'x-real-ip'
|
28 | ]);
|
29 | exports.fetchAndReturn = async (url) => {
|
30 | const response = await fetch(url);
|
31 |
|
32 | const headers = {};
|
33 | for (const [header, value] of response.headers.entries()) {
|
34 | if (excludedHeaders.has(header.toLowerCase()))
|
35 | continue;
|
36 | headers[header] = value;
|
37 | }
|
38 |
|
39 | if (!headers['content-type'])
|
40 | headers['content-type'] = getContentType(url_1.parse(url).path);
|
41 | return new Response(await response.body, {
|
42 | status: response.status,
|
43 | statusText: response.statusText,
|
44 | headers
|
45 | });
|
46 | };
|