summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/redirect_with_query_args.sjs
blob: 3359367ee0ea281fef587167a91450648d4c37d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * This file expects a query string that's the upper-cased version of a file to
 * be redirected to in the same directory.  The redirect will also include
 * added "secret data" as a query string.
 *
 * So if the request is `/path/redirect_with_query_args.sjs?FOO.JS` the redirect
 * will be to `/path/foo.js?SECRET_DATA`.
 **/

function handleRequest(request, response) {
  // The secret data to include in the redirect to make the redirect URL
  // easily detectable.
  const secretData = "SECRET_DATA";

  let pathBase = request.path.split("/").slice(0, -1).join("/");
  let targetFile = request.queryString.toLowerCase();
  let newUrl = `${pathBase}/${targetFile}?${secretData}`;

  response.setStatusLine(request.httpVersion, 302, "Found");
  response.setHeader("Cache-Control", "no-cache");
  response.setHeader("Location", newUrl, false);
}