(self)
| 387 | # Request header handler for default do_GET() path in |
| 388 | # SimpleHTTPRequestHandler.do_GET(self) below. |
| 389 | def send_head(self): |
| 390 | if self.headers.get('Range'): |
| 391 | path = self.translate_path(self.path) |
| 392 | try: |
| 393 | fsize = os.path.getsize(path) |
| 394 | f = open(path, 'rb') |
| 395 | except OSError: |
| 396 | self.send_error(404, f'File not found {path}') |
| 397 | return None |
| 398 | self.send_response(206) |
| 399 | ctype = self.guess_type(path) |
| 400 | self.send_header('Content-Type', ctype) |
| 401 | pieces = self.headers.get('Range').split('=')[1].split('-') |
| 402 | start = int(pieces[0]) if pieces[0] else 0 |
| 403 | end = int(pieces[1]) if pieces[1] else fsize - 1 |
| 404 | end = min(fsize - 1, end) |
| 405 | length = end - start + 1 |
| 406 | self.send_header('Content-Range', f'bytes {start}-{end}/{fsize}') |
| 407 | self.send_header('Content-Length', str(length)) |
| 408 | self.end_headers() |
| 409 | return f |
| 410 | else: |
| 411 | return SimpleHTTPRequestHandler.send_head(self) |
| 412 | |
| 413 | # Add COOP, COEP, CORP, and no-caching headers |
| 414 | def end_headers(self): |
nothing calls this directly
no test coverage detected