~fkfd/git.gmi

eb1bd1e074b81a428cb689d3a381e86e2fd530dd — Frederick Yin 1 year, 2 months ago b5b7457
Fix: response headers now terminate with CRLF
1 files changed, 8 insertions(+), 8 deletions(-)

M git-gmi/git.py
M git-gmi/git.py => git-gmi/git.py +8 -8
@@ 36,7 36,7 @@ class GitGmiRepo:
        return header

    def view_summary(self) -> str:
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self.generate_header()
        # show 3 recent commits
        recent_commits = self.get_commit_log()[:3]
        for cmt in recent_commits:


@@ 82,7 82,7 @@ class GitGmiRepo:
        return log  # reverse chronical order

    def view_log(self) -> str:
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self.generate_header()
        log = self.get_commit_log()
        for cmt in log:
            # looks like "2020-06-06 04:51:21 UTC"


@@ 112,7 112,7 @@ class GitGmiRepo:
    def view_commit(self, commit_str) -> str:
        commit = self.get_commit(commit_str)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self.generate_header()
            + f"{commit['id']} - {commit['author']} - {commit['time']}\n"
            + commit["msg"]


@@ 127,7 127,7 @@ class GitGmiRepo:

    def view_raw_commit(self, commit_str) -> str:
        commit = self.get_commit(commit_str)
        response = f"{STATUS_SUCCESS} {META_PLAINTEXT}\n" + commit["patch"]
        response = f"{STATUS_SUCCESS} {META_PLAINTEXT}\r\n" + commit["patch"]
        return response

    def get_refs(self) -> list:


@@ 143,7 143,7 @@ class GitGmiRepo:
        ]

    def view_refs(self) -> str:
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self.generate_header()
        refs = self.get_refs()
        for ref in refs:
            # HACK: filter out refs with slashes as remote branches


@@ 229,7 229,7 @@ class GitGmiRepo:
        contents = self.list_tree(tree, location)
        items = len(contents)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self.generate_header()
            + f"## {self.name}{'/' if location else ''}{'/'.join(location)}/"
            f" | {items} {'items' if items > 1 else 'item'}\n\n"


@@ 260,7 260,7 @@ class GitGmiRepo:
    def view_blob(self, branch: str, location=[]) -> str:
        blob = self.get_blob(branch, location)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self.generate_header()
            + f"## {self.name}/{'/'.join(location)} | {convert_filesize(blob.size)}\n\n"
            f"=> {blob.name}?raw view raw\n\n"


@@ 273,6 273,6 @@ class GitGmiRepo:
        blob = self.get_blob(branch, location)
        # if mimetypes can't make out the type, set it to plaintext
        guessed_mimetype = mimetypes.guess_type(blob.name)[0] or META_PLAINTEXT
        response = f"{STATUS_SUCCESS} {guessed_mimetype}\n"
        response = f"{STATUS_SUCCESS} {guessed_mimetype}\r\n"
        response += blob.data.decode("utf-8")
        return response