~james/core

ref: 452f17b75181d62d1d92016edecd38e1d70fecab core/web/src/lib/server/github/http.ts -rw-r--r-- 771 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export const noStore = (headers = new Headers()) => {
	headers.set("cache-control", "no-store");
	return headers;
};

export const redirectTo = (location: string) => {
	const headers = noStore();
	headers.set("location", location);
	return new Response(null, { status: 302, headers });
};

// reverse proxy terminates tls; url.protocol is http inside the worker
export const requestOrigin = (url: URL, headers: Headers) => {
	const forwarded = headers.get("x-forwarded-proto")?.split(",", 1)[0].trim().toLowerCase();
	const protocol = forwarded === "http" || forwarded === "https" ? `${forwarded}:` : url.protocol;
	return `${protocol}//${url.host}`;
};

export const isSecureRequest = (url: URL, headers: Headers) =>
	requestOrigin(url, headers).startsWith("https://");