Skip to content

Commit

Permalink
Default mime type to application/octet-stream for unrecognized file t…
Browse files Browse the repository at this point in the history
…ypes (nerfstudio-project#227)

* Default mime type to application/octet-stream if cannot guess

* format

* infra mime type change

* ruff

* Try shortening

---------

Co-authored-by: Brent Yi <[email protected]>
  • Loading branch information
ginazhouhuiwu and brentyi authored Jun 25, 2024
1 parent 202a251 commit aac5f78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit aac5f78

Please sign in to comment.