going-flying.com gemini git repository
e76db24be315dea3315204f6363161001a4816ed - Matthew Ernisse - 1612489461
fix some \n -> \r\n misses
diff --git a/git/gateway.py b/git/gateway.py index b0c9b0a..138f3f4 100644 --- a/git/gateway.py +++ b/git/gateway.py @@ -6,6 +6,8 @@ import sys # be careful when using print(); stdout is passed to the client. # this cgi uses \n as newline. +# +# Molly Brown wants \r\n as the line ender for the status line. def handle_cgi_request(path: str, query: str): @@ -14,9 +16,16 @@ def handle_cgi_request(path: str, query: str): # url: gemini://git.gemini.site/git/cgi/repo/src/static/css/[index.css] # path: /repo/src/static/css/[index.css] # path_trace = ['repo', 'src', 'static', 'css', 'index.css'] - path_trace = path[1:].split("/") - if path_trace == [""]: # empty path - print(f"{STATUS_SUCCESS} {META_GEMINI}") # welcome page +# path_trace = path[1:].split("/") +# if path_trace == [""]: # empty path + + # Update to work with Molly Brown. It appears that Molly Brown only + # adds slashes if there is a next path part in the URL, eg: + # /git/cgi/ -> PATH_INFO: "" + # /git/cgi/gemini.git/ -> PATH_INFO: "gemini.git" + path_trace = path.split("/") + if not path_trace or (len(path_trace) == 1 and not path_trace[0]): + print(f"{STATUS_SUCCESS} {META_GEMINI}\r\n") # welcome page print(f"# Welcome to {GIT_GMI_SITE_TITLE}") print("## Available repositories:") print("\n".join([f"=> {dir}/" for dir in listdir(GIT_CATALOG)])) @@ -25,26 +34,26 @@ def handle_cgi_request(path: str, query: str): try: repo = GitGmiRepo(path_trace[0], f"{GIT_CATALOG}/{path_trace[0]}") except FileNotFoundError: - print(STATUS_NOT_FOUND) + print(f'{STATUS_NOT_FOUND}\r\n') return if len(path_trace) > 1: view = path_trace[1] # e.g. summary, tree, log else: # gemini://git.gemini.site/git/cgi/<repo>/ - print("31 summary") + print("31 summary\r\n") return if view == "summary": try: print(repo.view_summary()) except: - print(STATUS_TEMPORARY_FAILURE) + print(f'{STATUS_TEMPORARY_FAILURE}\r\n') elif view == "tree": if len(path_trace) == 2: # gemini://git.gemini.site/git/cgi/<repo>/tree/ - print(f"31 {MAIN_BRANCH}/") + print(f"31 {MAIN_BRANCH}/\r\n") elif len(path_trace) > 2: # gemini://git.gemini.site/git/cgi/<repo>/tree/<branch>/ @@ -61,19 +70,19 @@ def handle_cgi_request(path: str, query: str): else: print(repo.view_blob(branch, location)) except FileNotFoundError: - print(STATUS_NOT_FOUND) + print(f'{STATUS_NOT_FOUND}\r\n') elif view == "log": try: print(repo.view_log()) except: - print(STATUS_TEMPORARY_FAILURE) + print(f'{STATUS_TEMPORARY_FAILURE}\r\n') elif view == "commit": try: commit_str = path_trace[2] except IndexError: - print("50 No commit id given") + print("50 No commit id given\r\n") return try: @@ -82,7 +91,7 @@ def handle_cgi_request(path: str, query: str): else: print(repo.view_commit(commit_str)) except FileNotFoundError: - print("50 No such commit") + print("50 No such commit\r\n") except: print(STATUS_TEMPORARY_FAILURE) @@ -90,7 +99,7 @@ def handle_cgi_request(path: str, query: str): try: print(repo.view_refs()) except: - print(STATUS_TEMPORARY_FAILURE) + print(f'{STATUS_TEMPORARY_FAILURE}\r\n') handle_cgi_request(environ.get("PATH_INFO"), environ.get("QUERY_STRING"))