Broken project to implement a cross-protocol browser in textual
protocols: Support http/https
| -rwxr-xr-x | browset.py | 16 | ||||
| -rw-r--r-- | protocol/http.py | 5 |
2 files changed, 16 insertions, 5 deletions
@@ -9,9 +9,17 @@ from mime.plaintext import Plaintext from mime.highlightedcode import HighlightedCode,mimetolexer from protocol.gemini import GeminiProtocol from protocol.data import DataProtocol +from protocol.http import HttpProtocol + +protocols = { + "gemini": GeminiProtocol, + "data": DataProtocol, + "http": HttpProtocol, + "https": HttpProtocol, +} class Browset(App): - url = "" + url = "about:blank" CSS_PATH = "browset.css" BINDINGS = [ Binding("ctrl+q,ctrl+c", "app.quit", "Quit", show=True), @@ -71,10 +79,8 @@ class Browset(App): self.history.append(self.url) self.url = url protocol = url.split(":")[0] - if protocol == "gemini": - (mime, fp) = GeminiProtocol.get(url) - elif protocol == "data": - (mime, fp) = DataProtocol.get(url) + if protocol in protocols: + (mime, fp) = protocols[protocol].get(url) else: (mime, fp) = ("error", ["Unsupported protocol: " + protocol]) diff --git a/protocol/http.py b/protocol/http.py new file mode 100644 index 0000000..2f9672c --- /dev/null +++ b/protocol/http.py @@ -0,0 +1,5 @@ +import requests +class HttpProtocol(): + def get(url): + r = requests.get(url) + return (r.headers['content-type'].split(';')[0], r) |