(self, path: str, include_body: bool = True)
| 2570 | return self.get(path, include_body=False) |
| 2571 | |
| 2572 | async def get(self, path: str, include_body: bool = True) -> None: |
| 2573 | # Set up our path instance variables. |
| 2574 | self.path = self.parse_url_path(path) |
| 2575 | del path # make sure we don't refer to path instead of self.path again |
| 2576 | absolute_path = self.get_absolute_path(self.root, self.path) |
| 2577 | self.absolute_path = self.validate_absolute_path(self.root, absolute_path) |
| 2578 | if self.absolute_path is None: |
| 2579 | return |
| 2580 | |
| 2581 | self.modified = self.get_modified_time() |
| 2582 | self.set_headers() |
| 2583 | |
| 2584 | if self.should_return_304(): |
| 2585 | self.set_status(304) |
| 2586 | return |
| 2587 | |
| 2588 | request_range = None |
| 2589 | range_header = self.request.headers.get("Range") |
| 2590 | if range_header: |
| 2591 | # As per RFC 2616 14.16, if an invalid Range header is specified, |
| 2592 | # the request will be treated as if the header didn't exist. |
| 2593 | request_range = httputil._parse_request_range(range_header) |
| 2594 | |
| 2595 | size = self.get_content_size() |
| 2596 | if request_range: |
| 2597 | start, end = request_range |
| 2598 | if start is not None and start < 0: |
| 2599 | start += size |
| 2600 | if start < 0: |
| 2601 | start = 0 |
| 2602 | if ( |
| 2603 | start is not None |
| 2604 | and (start >= size or (end is not None and start >= end)) |
| 2605 | ) or end == 0: |
| 2606 | # As per RFC 2616 14.35.1, a range is not satisfiable only: if |
| 2607 | # the first requested byte is equal to or greater than the |
| 2608 | # content, or when a suffix with length 0 is specified. |
| 2609 | # https://tools.ietf.org/html/rfc7233#section-2.1 |
| 2610 | # A byte-range-spec is invalid if the last-byte-pos value is present |
| 2611 | # and less than the first-byte-pos. |
| 2612 | self.set_status(416) # Range Not Satisfiable |
| 2613 | self.set_header("Content-Type", "text/plain") |
| 2614 | self.set_header("Content-Range", "bytes */%s" % (size,)) |
| 2615 | return |
| 2616 | if end is not None and end > size: |
| 2617 | # Clients sometimes blindly use a large range to limit their |
| 2618 | # download size; cap the endpoint at the actual file size. |
| 2619 | end = size |
| 2620 | # Note: only return HTTP 206 if less than the entire range has been |
| 2621 | # requested. Not only is this semantically correct, but Chrome |
| 2622 | # refuses to play audio if it gets an HTTP 206 in response to |
| 2623 | # ``Range: bytes=0-``. |
| 2624 | if size != (end or size) - (start or 0): |
| 2625 | self.set_status(206) # Partial Content |
| 2626 | self.set_header( |
| 2627 | "Content-Range", httputil._get_content_range(start, end, size) |
| 2628 | ) |
| 2629 | else: |
no test coverage detected