tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

vary.any.js (6747B)


      1 // META: global=window,worker
      2 // META: title=HTTP Cache - Vary
      3 // META: timeout=long
      4 // META: script=/common/utils.js
      5 // META: script=/common/get-host-info.sub.js
      6 // META: script=http-cache.js
      7 
      8 var tests = [
      9  {
     10    name: "HTTP cache reuses Vary response when request matches",
     11    requests: [
     12      {
     13        request_headers: [
     14          ["Foo", "1"]
     15        ],
     16        response_headers: [
     17          ["Expires", 5000],
     18          ["Last-Modified", -3000],
     19          ["Vary", "Foo"]
     20        ]
     21      },
     22      {
     23        request_headers: [
     24          ["Foo", "1"]
     25        ],
     26        expected_type: "cached"
     27      }
     28    ]
     29  },
     30  {
     31    name: "HTTP cache doesn't use Vary response when request doesn't match",
     32    requests: [
     33      {
     34        request_headers: [
     35          ["Foo", "1"]
     36        ],
     37        response_headers: [
     38          ["Expires", 5000],
     39          ["Last-Modified", -3000],
     40          ["Vary", "Foo"]
     41        ]
     42      },
     43      {
     44        request_headers: [
     45          ["Foo", "2"]
     46        ],
     47        expected_type: "not_cached"
     48      }
     49    ]
     50  },
     51  {
     52    name: "HTTP cache doesn't use Vary response when request omits variant header",
     53    requests: [
     54      {
     55        request_headers: [
     56          ["Foo", "1"]
     57        ],
     58        response_headers: [
     59          ["Expires", 5000],
     60          ["Last-Modified", -3000],
     61          ["Vary", "Foo"]
     62        ]
     63      },
     64      {
     65        expected_type: "not_cached"
     66      }
     67    ]
     68  },
     69  {
     70    name: "HTTP cache doesn't invalidate existing Vary response",
     71    requests: [
     72      {
     73        request_headers: [
     74          ["Foo", "1"]
     75        ],
     76        response_headers: [
     77          ["Expires", 5000],
     78          ["Last-Modified", -3000],
     79          ["Vary", "Foo"]
     80        ],
     81        response_body: http_content('foo_1')
     82      },
     83      {
     84        request_headers: [
     85          ["Foo", "2"]
     86        ],
     87        response_headers: [
     88          ["Expires", 5000],
     89          ["Last-Modified", -3000],
     90          ["Vary", "Foo"]
     91        ],
     92        expected_type: "not_cached",
     93        response_body: http_content('foo_2'),
     94      },
     95      {
     96        request_headers: [
     97          ["Foo", "1"]
     98        ],
     99        response_body: http_content('foo_1'),
    100        expected_type: "cached"
    101      }
    102    ]
    103  },
    104  {
    105    name: "HTTP cache doesn't pay attention to headers not listed in Vary",
    106    requests: [
    107      {
    108        request_headers: [
    109          ["Foo", "1"],
    110          ["Other", "2"]
    111        ],
    112        response_headers: [
    113          ["Expires", 5000],
    114          ["Last-Modified", -3000],
    115          ["Vary", "Foo"]
    116        ],
    117      },
    118      {
    119        request_headers: [
    120          ["Foo", "1"],
    121          ["Other", "3"]
    122        ],
    123        expected_type: "cached"
    124      }
    125    ]
    126  },
    127  {
    128    name: "HTTP cache reuses two-way Vary response when request matches",
    129    requests: [
    130      {
    131        request_headers: [
    132          ["Foo", "1"],
    133          ["Bar", "abc"]
    134        ],
    135        response_headers: [
    136          ["Expires", 5000],
    137          ["Last-Modified", -3000],
    138          ["Vary", "Foo, Bar"]
    139        ]
    140      },
    141      {
    142        request_headers: [
    143          ["Foo", "1"],
    144          ["Bar", "abc"]
    145        ],
    146        expected_type: "cached"
    147      }
    148    ]
    149  },
    150  {
    151    name: "HTTP cache doesn't use two-way Vary response when request doesn't match",
    152    requests: [
    153      {
    154        request_headers: [
    155          ["Foo", "1"],
    156          ["Bar", "abc"]
    157        ],
    158        response_headers: [
    159          ["Expires", 5000],
    160          ["Last-Modified", -3000],
    161          ["Vary", "Foo, Bar"]
    162        ]
    163      },
    164      {
    165        request_headers: [
    166          ["Foo", "2"],
    167          ["Bar", "abc"]
    168        ],
    169        expected_type: "not_cached"
    170      }
    171    ]
    172  },
    173  {
    174    name: "HTTP cache doesn't use two-way Vary response when request omits variant header",
    175    requests: [
    176      {
    177        request_headers: [
    178          ["Foo", "1"]
    179        ],
    180        response_headers: [
    181          ["Expires", 5000],
    182          ["Last-Modified", -3000],
    183          ["Vary", "Foo, Bar"]
    184        ]
    185      },
    186      {
    187        expected_type: "not_cached"
    188      }
    189    ]
    190  },
    191  {
    192    name: "HTTP cache reuses three-way Vary response when request matches",
    193    requests: [
    194      {
    195        request_headers: [
    196          ["Foo", "1"],
    197          ["Bar", "abc"],
    198          ["Baz", "789"]
    199        ],
    200        response_headers: [
    201          ["Expires", 5000],
    202          ["Last-Modified", -3000],
    203          ["Vary", "Foo, Bar, Baz"]
    204        ]
    205      },
    206      {
    207        request_headers: [
    208          ["Foo", "1"],
    209          ["Bar", "abc"],
    210          ["Baz", "789"]
    211        ],
    212        expected_type: "cached"
    213      }
    214    ]
    215  },
    216  {
    217    name: "HTTP cache doesn't use three-way Vary response when request doesn't match",
    218    requests: [
    219      {
    220        request_headers: [
    221          ["Foo", "1"],
    222          ["Bar", "abc"],
    223          ["Baz", "789"]
    224        ],
    225        response_headers: [
    226          ["Expires", 5000],
    227          ["Last-Modified", -3000],
    228          ["Vary", "Foo, Bar, Baz"]
    229        ]
    230      },
    231      {
    232        request_headers: [
    233          ["Foo", "2"],
    234          ["Bar", "abc"],
    235          ["Baz", "789"]
    236        ],
    237        expected_type: "not_cached"
    238      }
    239    ]
    240  },
    241  {
    242    name: "HTTP cache doesn't use three-way Vary response when request doesn't match, regardless of header order",
    243    requests: [
    244      {
    245        request_headers: [
    246          ["Foo", "1"],
    247          ["Bar", "abc4"],
    248          ["Baz", "789"]
    249        ],
    250        response_headers: [
    251          ["Expires", 5000],
    252          ["Last-Modified", -3000],
    253          ["Vary", "Foo, Bar, Baz"]
    254        ]
    255      },
    256      {
    257        request_headers: [
    258          ["Foo", "1"],
    259          ["Bar", "abc"],
    260          ["Baz", "789"]
    261        ],
    262        expected_type: "not_cached"
    263      }
    264    ]
    265  },
    266  {
    267    name: "HTTP cache uses three-way Vary response when both request and the original request omited a variant header",
    268    requests: [
    269      {
    270        request_headers: [
    271          ["Foo", "1"],
    272          ["Baz", "789"]
    273        ],
    274        response_headers: [
    275          ["Expires", 5000],
    276          ["Last-Modified", -3000],
    277          ["Vary", "Foo, Bar, Baz"]
    278        ]
    279      },
    280      {
    281        request_headers: [
    282          ["Foo", "1"],
    283          ["Baz", "789"]
    284        ],
    285        expected_type: "cached"
    286      }
    287    ]
    288  },
    289  {
    290    name: "HTTP cache doesn't use Vary response with a field value of '*'",
    291    requests: [
    292      {
    293        request_headers: [
    294          ["Foo", "1"],
    295          ["Baz", "789"]
    296        ],
    297        response_headers: [
    298          ["Expires", 5000],
    299          ["Last-Modified", -3000],
    300          ["Vary", "*"]
    301        ]
    302      },
    303      {
    304        request_headers: [
    305          ["*", "1"],
    306          ["Baz", "789"]
    307        ],
    308        expected_type: "not_cached"
    309      }
    310    ]
    311  }
    312 ];
    313 run_tests(tests);