slow-redirect.py (738B)
1 import time 2 3 def main(request, response): 4 """Simple handler that causes redirection. 5 6 The request should typically have two query parameters: 7 status - The status to use for the redirection. Defaults to 302. 8 location - The resource to redirect to. 9 """ 10 status = 302 11 delay = 2 12 if b"status" in request.GET: 13 try: 14 status = int(request.GET.first(b"status")) 15 except ValueError: 16 pass 17 18 if b"delay" in request.GET: 19 try: 20 delay = int(request.GET.first(b"delay")) 21 except ValueError: 22 pass 23 24 response.status = status 25 time.sleep(delay) 26 27 location = request.GET.first(b"location") 28 29 response.headers.set(b"Location", location)