Fix bug when requesting urls with ports

This commit is contained in:
MatthiasSaihttam 2021-09-25 09:04:27 -04:00
parent e351bc03d4
commit 7761c18fd5
2 changed files with 7 additions and 5 deletions

View File

@ -195,6 +195,7 @@ export default class GeminiServer {
let requestLine = "";
socket.on("data", d => {
// console.log("got data\n" + d.split("").map(c => c.charCodeAt().toString(16)).join(" "));
requestLine += d;
//If we have the end of the request
if (requestLine.includes("\r\n")) {
@ -206,10 +207,11 @@ export default class GeminiServer {
}else {
//TODO: What if the URL doesn't have a protocol or a domain at all?
//Make sure that the SNI negotiated name matches the hostname in the request
const url = new URL(requestLine.slice(0, -2))
if (url.host !== socket.servername) {
//TODO: make this line not a joke
socket.write("40 Heck you\r\n");
const url = new URL(requestLine.slice(0, -2));
//url.hostname is the servername/domain name, url.host could also have a port
//TODO: check that the port matches the port that we're running on
if (url.hostname !== socket.servername) {
socket.write("40 Negotiated SNI host doesn't match requested URL\r\n");
socket.end();
}else {
//Responding

View File

@ -1,6 +1,6 @@
{
"name": "astronomical-theater",
"version": "v2.0.3",
"version": "v2.0.5",
"author": "Matthias",
"license": "CC0-1.0",
"type": "module",