File: thumbnails_update.sjs

package info (click to toggle)
firefox-esr 128.13.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,230,012 kB
  • sloc: cpp: 7,103,971; javascript: 6,088,450; ansic: 3,653,980; python: 1,212,330; xml: 594,604; asm: 420,652; java: 182,969; sh: 71,124; makefile: 20,747; perl: 13,449; objc: 12,399; yacc: 4,583; cs: 3,846; pascal: 2,973; lex: 1,720; ruby: 1,194; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (57 lines) | stat: -rw-r--r-- 2,674 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// This server-side script is used for browser_thumbnails_update.  One of the
// main things it must do in all cases is ensure a Cache-Control: no-store
// header, so the foreground capture doesn't interfere with the testing.

// If the querystring is "simple", then all it does it return some content -
// it doesn't really matter what that content is.

// Otherwise, its main role is that it must return different *content* for the
// second request than it did for the first.
// Also, it should be able to return an error response when requested for the
// second response.
// So the basic tests will be to grab the thumbnail, then request it to be
// grabbed again:
// * If the second request succeeded, the new thumbnail should exist.
// * If the second request is an error, the new thumbnail should be ignored.

function handleRequest(aRequest, aResponse) {
  aResponse.setHeader("Content-Type", "text/html;charset=utf-8", false);
  // we want to disable gBrowserThumbnails on-load capture for these responses,
  // so set as a "no-store" response.
  aResponse.setHeader("Cache-Control", "no-store");

  // for the simple test - just return some content.
  if (aRequest.queryString == "simple") {
    aResponse.write("<html><body></body></html>");
    aResponse.setStatusLine(aRequest.httpVersion, 200, "Its simply OK");
    return;
  }

  // it's one of the more complex tests where the first request for the given
  // URL must return different content than the second, and possibly an error
  // response for the second
  let doneError = getState(aRequest.queryString);
  if (!doneError) {
    // first request - return a response with a green body and 200 response.
    aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's green");
    aResponse.write("<html><body bgcolor=00ff00></body></html>");
    // set the  state so the next request does the "second request" thing below.
    setState(aRequest.queryString, "yep");
  } else {
    // second request - this will be done by the b/g service.
    // We always return a red background, but depending on the query string we
    // return either a 200 or 401 response.
    if (aRequest.queryString == "fail") {
      aResponse.setStatusLine(aRequest.httpVersion, 401, "Oh no you don't");
    } else {
      aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's red");
    }
    aResponse.write("<html><body bgcolor=ff0000></body></html>");
    // reset the error state incase this ends up being reused for the
    // same url and querystring.
    setState(aRequest.queryString, "");
  }
}