~sotirisp/qute-gemini

3113b038a6344f852a3a14a1e55fe8cd8d97af92 — Sotiris Papatheodorou 8 months ago 39db139
Fix bug in media type detection

Forgot media types can have subtypes, suffixes and parameters
1 files changed, 6 insertions(+), 6 deletions(-)

M qute-gemini
M qute-gemini => qute-gemini +6 -6
@@ 78,10 78,10 @@ def gemini_fetch_url(url: str) -> Tuple[str, str]:
        # Get header and check for redirects
        fp = s.makefile("rb")
        header = fp.readline().decode("UTF-8").strip()
        status, mime = header.split()[:2]
        status, media_type = header.split()[:2]
        # Follow redirects
        if status.startswith("3"):
            url = gemini_absolutise_url(url, mime)
            url = gemini_absolutise_url(url, media_type)
            parsed_url = urllib.parse.urlparse(url)
        # Otherwise we're done
        else:


@@ 89,14 89,14 @@ def gemini_fetch_url(url: str) -> Tuple[str, str]:
    # Fail if transaction was not successful, user input or a certificate was
    # required
    if status.startswith("2"):
        if mime == "text/gemini":
        if media_type.startswith("text/gemini"):
            # Decode according to declared charset
            mime, mime_opts = cgi.parse_header(mime)
            media_type, media_type_opts = cgi.parse_header(media_type)
            body = fp.read()
            body = body.decode(mime_opts.get("charset", "UTF-8"))
            body = body.decode(media_type_opts.get("charset", "UTF-8"))
            return body, ""
        else:
            return "", "Received non-gemtext content: " + mime
            return "", "Received non-gemtext content: " + media_type
    else:
        return "", "Received Gemini status " + status