Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default mime type to application/octet-stream for unrecognized file types #227

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/viser/_viser.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,8 @@ def send_file_download(
chunk_size: Number of bytes to send at a time.
"""
mime_type = mimetypes.guess_type(filename, strict=False)[0]
assert (
mime_type is not None
), f"Could not guess MIME type from filename {filename}!"
if mime_type is None:
mime_type = "application/octet-stream"

from ._gui_api import _make_unique_id

Expand Down
5 changes: 4 additions & 1 deletion src/viser/infra/_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ async def viser_http_server(

use_gzip = "gzip" in request_headers.get("Accept-Encoding", "")

mime_type = mimetypes.guess_type(relpath)[0]
if mime_type is None:
mime_type = "application/octet-stream"
response_headers = {
"Content-Type": str(mimetypes.MimeTypes().guess_type(relpath)[0]),
"Content-Type": mime_type,
}

if source_path not in file_cache:
Expand Down
Loading