Stay on https: through redirects.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3744 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-09 01:36:29 +00:00
parent 86aa5e4d1e
commit ec9e9151dc
2 changed files with 5 additions and 4 deletions

View File

@ -451,7 +451,7 @@ async function blobHandler(request, response, blobId, uri) {
} }
if (!uri) { if (!uri) {
response.writeHead(303, {"Location": 'http://' + request.headers.host + blobId + '/', "Content-Length": "0"}); response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + blobId + '/', "Content-Length": "0"});
response.end(data); response.end(data);
return; return;
} }
@ -542,7 +542,7 @@ loadSettings().then(function() {
httpd.all("", function(request, response) { httpd.all("", function(request, response) {
var match; var match;
if (request.uri === "/" || request.uri === "") { if (request.uri === "/" || request.uri === "") {
response.writeHead(303, {"Location": 'http://' + request.headers.host + gGlobalSettings.index, "Content-Length": "0"}); response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + gGlobalSettings.index, "Content-Length": "0"});
return response.end(); return response.end();
} else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) { } else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]); return blobHandler(request, response, match[1], match[2]);
@ -551,7 +551,7 @@ loadSettings().then(function() {
} else if (match = /^\/static(\/.*)/.exec(request.uri)) { } else if (match = /^\/static(\/.*)/.exec(request.uri)) {
return staticFileHandler(request, response, null, match[1]); return staticFileHandler(request, response, null, match[1]);
} else if (match = /^\/scope$/.exec(request.uri)) { } else if (match = /^\/scope$/.exec(request.uri)) {
response.writeHead(303, {"Location": 'http://' + request.headers.host + '/speedscope/#profileURL=http://' + request.headers.host + '/trace', "Content-Length": "0"}); response.writeHead(303, {"Location": (request.client.tls ? 'https://' : 'http://') + request.headers.host + '/speedscope/#profileURL=' + (request.client.tls ? 'https' : 'http://') + request.headers.host + '/trace', "Content-Length": "0"});
return response.end(data); return response.end(data);
} else if (match = /^\/speedscope\/([\.\w-]*)$/.exec(request.uri)) { } else if (match = /^\/speedscope\/([\.\w-]*)$/.exec(request.uri)) {
return speedScopeHandler(request, response, match[1]); return speedScopeHandler(request, response, match[1]);

View File

@ -50,7 +50,7 @@ function Request(method, uri, version, headers, body, client) {
} }
this.version = version; this.version = version;
this.headers = headers; this.headers = headers;
this.client = {peerName: client.peerName}; this.client = {peerName: client.peerName, tls: client.tls};
this.body = body; this.body = body;
return this; return this;
} }
@ -471,6 +471,7 @@ if (tildefriends.https_port) {
return secureSocket.listen(kBacklog, async function() { return secureSocket.listen(kBacklog, async function() {
try { try {
var client = await secureSocket.accept(); var client = await secureSocket.accept();
client.tls = true;
const kCertificatePath = "data/httpd/certificate.pem"; const kCertificatePath = "data/httpd/certificate.pem";
const kPrivateKeyPath = "data/httpd/privatekey.pem"; const kPrivateKeyPath = "data/httpd/privatekey.pem";