File: handle-headers-retry.py

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (43 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (12)
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
import importlib
header_helpers = importlib.import_module("storage-access-api.resources.header-helpers")

# Sets the `Activate-Storage-Access` response header to a `retry` value
# corresponding to the supplied `allowed_origin`.
def maybe_set_retry(allowed_origin, response):
  if allowed_origin is None:
    return

  if allowed_origin == b'*':
    retry_response = b'retry; allowed-origin=*'
  elif allowed_origin == b'':
    retry_response = b'retry'
  else:
    retry_response = b'retry; allowed-origin=\"' + allowed_origin + b'\"'
  response.headers.set(b'Activate-Storage-Access', retry_response)

def main(request, response):
  request_params = request.GET
  if b'key' in request_params:
    key = request_params.first(b'key')
  # Do not handle requests without a key parameter.
  else:
    return (400, [], b'')

  allowed_origin = request_params.first(b'retry-allowed-origin', None)
  storage_access_status = request.headers.get(b'sec-fetch-storage-access')

  # If a request has been successfully retried and set to active, store its
  # headers under a modified key so they can be retrieved independently of
  # the initial request's headers.
  if storage_access_status == b'active':
      key += b'active'
  maybe_set_retry(allowed_origin, response)

  # Check if the request should redirect.
  header_helpers.maybe_set_redirect(request_params, response, storage_access_status)

  request.server.stash.put(header_helpers.make_stash_key(key, request_params),
                           header_helpers.get_stashable_headers(request.headers),
                           header_helpers.RETRIEVAL_PATH)

  return header_helpers.make_response_body(request_params)