| 651 | | status = '200 OK' |
|---|
| 652 | | headers = {} |
|---|
| 653 | | mime_type = mimetypes.guess_type(file_path)[0] |
|---|
| 654 | | if mime_type: |
|---|
| 655 | | headers['Content-Type'] = mime_type |
|---|
| 656 | | output = [fp.read()] |
|---|
| 657 | | fp.close() |
|---|
| | 652 | # This is a very simple implementation of conditional GET with |
|---|
| | 653 | # the Last-Modified header. It makes media files a bit speedier |
|---|
| | 654 | # because the files are only read off disk for the first |
|---|
| | 655 | # request (assuming the browser/client supports conditional |
|---|
| | 656 | # GET). |
|---|
| | 657 | mtime = http_date(os.stat(file_path)[stat.ST_MTIME]) |
|---|
| | 658 | headers = {'Last-Modified': mtime} |
|---|
| | 659 | if environ.get('HTTP_IF_MODIFIED_SINCE', None) == mtime: |
|---|
| | 660 | status = '304 NOT MODIFIED' |
|---|
| | 661 | output = [] |
|---|
| | 662 | else: |
|---|
| | 663 | status = '200 OK' |
|---|
| | 664 | mime_type = mimetypes.guess_type(file_path)[0] |
|---|
| | 665 | if mime_type: |
|---|
| | 666 | headers['Content-Type'] = mime_type |
|---|
| | 667 | output = [fp.read()] |
|---|
| | 668 | fp.close() |
|---|