MCPcopy Create free account
hub / github.com/EasyIME/PIME / get

Method get

python/python3/tornado/web.py:2606–2687  ·  view source on GitHub ↗
(self, path: str, include_body: bool = True)

Source from the content-addressed store, hash-verified

2604 return self.get(path, include_body=False)
2605
2606 async def get(self, path: str, include_body: bool = True) -> None:
2607 # Set up our path instance variables.
2608 self.path = self.parse_url_path(path)
2609 del path # make sure we don't refer to path instead of self.path again
2610 absolute_path = self.get_absolute_path(self.root, self.path)
2611 self.absolute_path = self.validate_absolute_path(self.root, absolute_path)
2612 if self.absolute_path is None:
2613 return
2614
2615 self.modified = self.get_modified_time()
2616 self.set_headers()
2617
2618 if self.should_return_304():
2619 self.set_status(304)
2620 return
2621
2622 request_range = None
2623 range_header = self.request.headers.get("Range")
2624 if range_header:
2625 # As per RFC 2616 14.16, if an invalid Range header is specified,
2626 # the request will be treated as if the header didn't exist.
2627 request_range = httputil._parse_request_range(range_header)
2628
2629 size = self.get_content_size()
2630 if request_range:
2631 start, end = request_range
2632 if start is not None and start < 0:
2633 start += size
2634 if start < 0:
2635 start = 0
2636 if (
2637 start is not None
2638 and (start >= size or (end is not None and start >= end))
2639 ) or end == 0:
2640 # As per RFC 2616 14.35.1, a range is not satisfiable only: if
2641 # the first requested byte is equal to or greater than the
2642 # content, or when a suffix with length 0 is specified.
2643 # https://tools.ietf.org/html/rfc7233#section-2.1
2644 # A byte-range-spec is invalid if the last-byte-pos value is present
2645 # and less than the first-byte-pos.
2646 self.set_status(416) # Range Not Satisfiable
2647 self.set_header("Content-Type", "text/plain")
2648 self.set_header("Content-Range", "bytes */%s" % (size,))
2649 return
2650 if end is not None and end > size:
2651 # Clients sometimes blindly use a large range to limit their
2652 # download size; cap the endpoint at the actual file size.
2653 end = size
2654 # Note: only return HTTP 206 if less than the entire range has been
2655 # requested. Not only is this semantically correct, but Chrome
2656 # refuses to play audio if it gets an HTTP 206 in response to
2657 # ``Range: bytes=0-``.
2658 if size != (end or size) - (start or 0):
2659 self.set_status(206) # Partial Content
2660 self.set_header(
2661 "Content-Range", httputil._get_content_range(start, end, size)
2662 )
2663 else:

Callers 1

headMethod · 0.95

Calls 13

parse_url_pathMethod · 0.95
get_absolute_pathMethod · 0.95
get_modified_timeMethod · 0.95
set_headersMethod · 0.95
should_return_304Method · 0.95
get_content_sizeMethod · 0.95
get_contentMethod · 0.95
set_statusMethod · 0.80
set_headerMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected