File: handle-headers-retry.py

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; 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)