Optionally enforce an HTTP => HTTPS redirect.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4116 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
3b00b31e87
commit
4d4cc92150
@ -27,6 +27,11 @@ const k_global_settings = {
|
||||
default_value: undefined,
|
||||
description: 'Code of conduct presented at sign-in.',
|
||||
},
|
||||
http_redirect: {
|
||||
type: 'string',
|
||||
default_value: undefined,
|
||||
description: 'If connecting by HTTP and HTTPS is configured, Location header prefix (ie, "https://example.com")',
|
||||
},
|
||||
};
|
||||
|
||||
var gGlobalSettings = {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as sha1 from './sha1.js';
|
||||
import * as core from './core.js';
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -505,10 +506,19 @@ function handleConnection(client) {
|
||||
result.path,
|
||||
`HTTP/1.${result.minor_version}`,
|
||||
];
|
||||
|
||||
headers = Object.fromEntries(Object.entries(result.headers).map(x => [x[0].toLowerCase(), x[1]]));
|
||||
parsing_header = false;
|
||||
inputBuffer = inputBuffer.slice(result.bytes_parsed);
|
||||
|
||||
if (!client.tls && tildefriends.https_port && core.globalSettings.http_redirect) {
|
||||
let requestObject = new Request(request[0], request[1], request[2], headers, body, client);
|
||||
let response = new Response(requestObject, client);
|
||||
response.writeHead(303, {"Location": `${core.globalSettings.http_redirect}${result.path}`, "Content-Length": "0"});
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (headers["content-length"] != undefined) {
|
||||
bodyToRead = parseInt(headers["content-length"]);
|
||||
if (bodyToRead > 16 * 1024 * 1024) {
|
||||
|
Loading…
Reference in New Issue
Block a user