render-blocking-stylesheet.py (750B)
1 import time 2 3 4 # This handler blocks a GET request for the given key until a matching POST is 5 # made with the same key. This allows a test to load a resource and manually 6 # control when the response is received. 7 def main(request, response): 8 key = request.GET.first(b'key') 9 10 if request.method == 'POST': 11 # Received result data from target page 12 request.server.stash.put(key, 'doResponse') 13 return 'done' 14 else: 15 poll_delay_sec = 0.1 16 17 # Wait until the caller POSTs before responding. 18 while request.server.stash.take(key) is None: 19 time.sleep(poll_delay_sec) 20 21 status = 200 22 headers = [('Content-Type', 'text/css')] 23 body = '' 24 return (status, headers, body)