(self, path: str, include_body: bool = True)
| 2788 | return self.get(path, include_body=False) |
| 2789 | |
| 2790 | async def get(self, path: str, include_body: bool = True) -> None: |
| 2791 | # Set up our path instance variables. |
| 2792 | self.path = self.parse_url_path(path) |
| 2793 | del path # make sure we don't refer to path instead of self.path again |
| 2794 | absolute_path = self.get_absolute_path(self.root, self.path) |
| 2795 | self.absolute_path = self.validate_absolute_path(self.root, absolute_path) |
| 2796 | if self.absolute_path is None: |
| 2797 | return |
| 2798 | |
| 2799 | self.modified = self.get_modified_time() |
| 2800 | self.set_headers() |
| 2801 | |
| 2802 | if self.should_return_304(): |
| 2803 | self.set_status(304) |
| 2804 | return |
| 2805 | |
| 2806 | request_range = None |
| 2807 | range_header = self.request.headers.get("Range") |
| 2808 | if range_header: |
| 2809 | # As per RFC 2616 14.16, if an invalid Range header is specified, |
| 2810 | # the request will be treated as if the header didn't exist. |
| 2811 | request_range = httputil._parse_request_range(range_header) |
| 2812 | |
| 2813 | size = self.get_content_size() |
| 2814 | if request_range: |
| 2815 | start, end = request_range |
| 2816 | if start is not None and start < 0: |
| 2817 | start += size |
| 2818 | if start < 0: |
| 2819 | start = 0 |
| 2820 | if ( |
| 2821 | start is not None |
| 2822 | and (start >= size or (end is not None and start >= end)) |
| 2823 | ) or end == 0: |
| 2824 | # As per RFC 2616 14.35.1, a range is not satisfiable only: if |
| 2825 | # the first requested byte is equal to or greater than the |
| 2826 | # content, or when a suffix with length 0 is specified. |
| 2827 | # https://tools.ietf.org/html/rfc7233#section-2.1 |
| 2828 | # A byte-range-spec is invalid if the last-byte-pos value is present |
| 2829 | # and less than the first-byte-pos. |
| 2830 | self.set_status(416) # Range Not Satisfiable |
| 2831 | self.set_header("Content-Type", "text/plain") |
| 2832 | self.set_header("Content-Range", f"bytes */{size}") |
| 2833 | return |
| 2834 | if end is not None and end > size: |
| 2835 | # Clients sometimes blindly use a large range to limit their |
| 2836 | # download size; cap the endpoint at the actual file size. |
| 2837 | end = size |
| 2838 | # Note: only return HTTP 206 if less than the entire range has been |
| 2839 | # requested. Not only is this semantically correct, but Chrome |
| 2840 | # refuses to play audio if it gets an HTTP 206 in response to |
| 2841 | # ``Range: bytes=0-``. |
| 2842 | if size != (end or size) - (start or 0): |
| 2843 | self.set_status(206) # Partial Content |
| 2844 | self.set_header( |
| 2845 | "Content-Range", httputil._get_content_range(start, end, size) |
| 2846 | ) |
| 2847 | else: |
no test coverage detected