Skip to content

Commit d89057c

Browse files
committed
🔨 Handle gopher-sourced MIME types better
1 parent c257a1c commit d89057c

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/rogallo/data/config.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ class Configuration:
2929
command_line_on_top: bool = False
3030
"""Should the command line live at the top of the screen?"""
3131

32-
displayable_content_types: list[str] = field(
33-
default_factory=lambda: [
34-
"text/gemini",
35-
"text/plain",
36-
]
37-
)
32+
displayable_content_types: list[str] = field(default_factory=list)
3833
"""The content types that can be displayed in the viewer."""
3934

4035
handle_ansi_escape_sequences: bool = True

src/rogallo/screens/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,12 @@ def _is_displayable(self, mime_type: str | None) -> bool:
451451
"""
452452
if isinstance(mime_type, str):
453453
mime_type, _, _ = mime_type.partition(";")
454-
return mime_type in load_configuration().displayable_content_types
454+
return mime_type in {
455+
"text/gemini",
456+
"text/plain",
457+
"text/gopher-menu",
458+
*load_configuration().displayable_content_types,
459+
}
455460

456461
async def _handle_input_request(
457462
self, location: GeminiURI, prompt: str, sensitive: bool
@@ -696,6 +701,11 @@ async def _load_from_gopher(self, request: OpenLocation) -> None:
696701
uri = request.location
697702
assert isinstance(uri, GopherURI)
698703

704+
mime_type = ItemType(uri.item_type).mime_type
705+
if not self._is_displayable(mime_type):
706+
self.post_message(OpenUnsupportedMIMEType(uri, mime_type))
707+
return
708+
699709
try:
700710
self._command_line.working = True
701711
self.post_message(
@@ -704,7 +714,7 @@ async def _load_from_gopher(self, request: OpenLocation) -> None:
704714
location=uri,
705715
original_location=uri,
706716
content=(await GopherClient().request(uri)).text,
707-
mime_type=ItemType(uri.item_type).mime_type,
717+
mime_type=mime_type,
708718
),
709719
original_request=request,
710720
)
@@ -881,8 +891,8 @@ async def _open_unsupported_mime_type(
881891
message: The message containing the unsupported MIME type.
882892
"""
883893

884-
# There's no reason why we should be here for Finger or Gopher URIs.
885-
if isinstance(message.location, (FingerURI, GopherURI)):
894+
# There's no reason why we should be here for Finger URIs.
895+
if isinstance(message.location, FingerURI):
886896
self.notify(
887897
f"Unexpected request to open {message.location}: please let Dave know",
888898
severity="warning",
@@ -911,7 +921,7 @@ async def _open_unsupported_mime_type(
911921
if open_uri:
912922
open_in_browser(
913923
str(message.location)
914-
if isinstance(message.location, GeminiURI)
924+
if isinstance(message.location, (GeminiURI, GopherURI))
915925
else message.location.resolve().as_uri()
916926
)
917927

0 commit comments

Comments
 (0)