blob: f783c8530c4386321c6da8e7be1ff4732074917d (
plain)
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
|
"""Automatic beacon store server.
- When a request body is not specified, serves a 200 response whose body
contains the stored value from the last automatic beacon. If the stored value
doesn't exist, serves a 200 response with an empty body.
- When a request body is specified, stores the data in the body and serves a 200
response without body.
"""
# Use an arbitrary key since `request.server.stash.put` expects a valid UUID.
BEACON_KEY = "0c02dba4-f01e-11ed-a05b-0242ac120003"
def main(request, response):
# Requests with a body imply they were sent as an automatic beacon for
# reserved.top_navigation. Note that this only stores the most recent beacon
# that was sent.
if request.body:
request.server.stash.put(BEACON_KEY, request.body)
return (200, [], b"")
# Requests without a body imply they were sent as the request from
# nextAutomaticBeacon().
data = request.server.stash.take(BEACON_KEY)
if not data and data != "":
return (200, [], b"<Not set>")
return (200, [], data)
|