Skip to content

Commit

Permalink
Allow a fast redirect to the new domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Apr 9, 2024
1 parent 07fb4d1 commit 64d7a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions connection.pike
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,15 @@ void session_cleanup() {
__async__ void http_request(Protocols.HTTP.Server.Request req)
{
req->misc->session = await(G->G->DB->load_session(req->cookies->session));
if (string dest = req->request_type == "GET" && req->misc->session->autoxfr) {
//This check shouldn't be necessary; the session value can't easily be set except on this one host.
string host = deduce_host(req->request_headers);
if (host == "sikorsky.rosuav.com") {
req->response_and_finish(redirect("https://" + dest + req->full_query));
return;
}
//Otherwise carry on as if the autoxfr marker wasn't there. (This also applies to non-GET requests.)
}
//TODO maybe: Refresh the login token. Currently the tokens don't seem to expire,
//but if they do, we can get the refresh token via authcookie (if present).
[function handler, array args] = find_http_handler(req->not_query);
Expand Down
6 changes: 6 additions & 0 deletions modules/http/xfr.pike
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ inherit http_endpoint;
mapping xfr_cookie = ([]); //NOT retained and not shared either.
__async__ mapping(string:mixed) http_request(Protocols.HTTP.Server.Request req) {
string host = deduce_host(req->request_headers);
if (string dest = host == "sikorsky.rosuav.com" && req->misc->session->cookie && req->variables->dest) {
//Set a default destination
if ((<"sikorsky.mustardmine.com", "gideon.mustardmine.com", "mustardmine.com">)[dest])
req->misc->session->autoxfr = dest;
return redirect("https://mustardmine.com/");
}
if (string sess = host == "sikorsky.rosuav.com" && req->misc->session->cookie) {
m_delete(xfr_cookie, xfr_cookie[sess]); //If we already have another, remove it
string xfr = MIME.encode_base64("xf-" + random_string(9));
Expand Down

0 comments on commit 64d7a43

Please sign in to comment.