| 463 | print(f'do_POST: unexpected POST: {urlinfo}') |
| 464 | |
| 465 | def do_GET(self): |
| 466 | info = urlparse(self.path) |
| 467 | if info.path == '/run_harness': |
| 468 | if DEBUG: |
| 469 | print('[server startup]') |
| 470 | self.send_response(200) |
| 471 | self.send_header('Content-type', 'text/html') |
| 472 | self.end_headers() |
| 473 | self.wfile.write(read_binary(test_file('browser_harness.html'))) |
| 474 | elif info.path.startswith('/status/'): |
| 475 | code_str = info.path[len('/status/'):] |
| 476 | code = int(code_str) |
| 477 | if code in {301, 302, 303, 307, 308}: |
| 478 | # Redirect to /status/200 |
| 479 | self.send_response(code) |
| 480 | self.send_header('Location', '/status/200') |
| 481 | self.end_headers() |
| 482 | elif code == 200: |
| 483 | self.send_response(200) |
| 484 | self.send_header('Content-type', 'text/plain') |
| 485 | self.end_headers() |
| 486 | self.wfile.write(b'OK') |
| 487 | else: |
| 488 | self.send_error(400, f'Not implemented for {code}') |
| 489 | elif 'report_' in self.path: |
| 490 | # for debugging, tests may encode the result and their own url (window.location) as result|url |
| 491 | if '|' in self.path: |
| 492 | path, url = self.path.split('|', 1) |
| 493 | else: |
| 494 | path = self.path |
| 495 | url = '?' |
| 496 | if DEBUG: |
| 497 | print('[server response:', path, url, ']') |
| 498 | if out_queue.empty(): |
| 499 | out_queue.put(path) |
| 500 | else: |
| 501 | # a badly-behaving test may send multiple xhrs with reported results; we just care |
| 502 | # about the first (if we queued the others, they might be read as responses for |
| 503 | # later tests, or maybe the test sends more than one in a racy manner). |
| 504 | # we place 'None' in the queue here so that the outside knows something went wrong |
| 505 | # (none is not a valid value otherwise; and we need the outside to know because if we |
| 506 | # raise an error in here, it is just swallowed in python's webserver code - we want |
| 507 | # the test to actually fail, which a webserver response can't do). |
| 508 | out_queue.put(None) |
| 509 | raise Exception('browser harness error, excessive response to server - test must be fixed! "%s"' % self.path) |
| 510 | self.send_response(200) |
| 511 | self.send_header('Content-type', 'text/plain') |
| 512 | self.send_header('Connection', 'close') |
| 513 | self.end_headers() |
| 514 | self.wfile.write(b'OK') |
| 515 | |
| 516 | elif info.path == '/check': |
| 517 | self.send_response(200) |
| 518 | self.send_header('Content-type', 'text/html') |
| 519 | self.end_headers() |
| 520 | if not in_queue.empty(): |
| 521 | # there is a new test ready to be served |
| 522 | url, dir = in_queue.get() |