redirect_301.sjs (763B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /** 6 * A page that performs 301 redirection to the given 'src'. 7 */ 8 9 "use strict"; 10 11 function handleRequest(request, response) { 12 let query = new URLSearchParams(request.queryString); 13 14 // The 'src' must be included. 15 if (!query.has("src")) { 16 throw Error("No 'src' in the query string"); 17 } 18 19 response.setStatusLine(request.httpVersion, 301, "Moved Permanently"); 20 response.setHeader("Location", query.get("src")); 21 response.setHeader("Cache-Control", "no-cache", false); 22 23 // Optional body for 301 response 24 response.write("Redirecting..."); 25 }