(self)
| 575 | # Processes HTTP request back to the browser. |
| 576 | class HTTPHandler(SimpleHTTPRequestHandler): |
| 577 | def send_head(self): |
| 578 | global page_last_served_time |
| 579 | path = self.translate_path(self.path) |
| 580 | f = None |
| 581 | |
| 582 | # A browser has navigated to this page - check which PID got spawned for |
| 583 | # the browser |
| 584 | global navigation_has_occurred |
| 585 | if not navigation_has_occurred and current_browser_processes is None: |
| 586 | detect_browser_processes() |
| 587 | |
| 588 | navigation_has_occurred = True |
| 589 | |
| 590 | if os.path.isdir(path): |
| 591 | if not self.path.endswith('/'): |
| 592 | self.send_response(301) |
| 593 | self.send_header("Location", self.path + "/") |
| 594 | self.end_headers() |
| 595 | return None |
| 596 | for index in "index.html", "index.htm": |
| 597 | index = os.path.join(path, index) |
| 598 | if os.path.isfile(index): |
| 599 | path = index |
| 600 | break |
| 601 | else: |
| 602 | # Manually implement directory listing support. |
| 603 | return self.list_directory(path) |
| 604 | |
| 605 | try: |
| 606 | f = open(path, 'rb') |
| 607 | except OSError: |
| 608 | self.send_error(404, "File not found: " + path) |
| 609 | return None |
| 610 | |
| 611 | self.send_response(200) |
| 612 | guess_file_type = path |
| 613 | # All files of type x.gz are served as gzip-compressed, which means the |
| 614 | # browser will transparently decode the file before passing the |
| 615 | # uncompressed bytes to the JS page. |
| 616 | # Note: In a slightly silly manner, detect files ending with "gz" and not |
| 617 | # ".gz", since both Unity and UE4 generate multiple files with .jsgz, |
| 618 | # .datagz, .memgz, .symbolsgz suffixes and so on, so everything goes. |
| 619 | # Note 2: If the JS application would like to receive the actual bits of a |
| 620 | # gzipped file, instead of having the browser decompress it immediately, |
| 621 | # then it can't use the suffix .gz when using emrun. |
| 622 | # To work around, one can use the suffix .gzip instead. |
| 623 | if path.lower().endswith('gz'): |
| 624 | self.send_header('Content-Encoding', 'gzip') |
| 625 | logv('Serving ' + path + ' as gzip-compressed.') |
| 626 | guess_file_type = guess_file_type[:-2] |
| 627 | if guess_file_type.endswith('.'): |
| 628 | guess_file_type = guess_file_type[:-1] |
| 629 | elif path.lower().endswith('br'): |
| 630 | self.send_header('Content-Encoding', 'br') |
| 631 | logv('Serving ' + path + ' as brotli-compressed.') |
| 632 | guess_file_type = guess_file_type[:-2] |
| 633 | if guess_file_type.endswith('.'): |
| 634 | guess_file_type = guess_file_type[:-1] |
nothing calls this directly
no test coverage detected