Skip to content

Commit e100fe6

Browse files
committed
Fix hostname prefix detection with HTTPS
1 parent d5e801b commit e100fe6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/http-handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TLSSocket } from 'tls';
12
import * as http from 'http';
23
import * as http2 from 'http2';
34

@@ -36,7 +37,10 @@ function createHttpRequestHandler(options: {
3637
rootDomain: string
3738
}): RequestHandler {
3839
return async function handleRequest(req, res) {
39-
const url = new URL(req.url!, `http://${req.headers.host}`);
40+
const protocol = `http${req.socket instanceof TLSSocket ? 's' : ''}`;
41+
const url = new URL(req.url!, `${protocol}://${
42+
req.headers[':authority'] ?? req.headers['host']
43+
}`);
4044
const path = url.pathname;
4145

4246
// --- A few initial administrative endpoints, that don't support CORS etc etc ---

0 commit comments

Comments
 (0)