~earboxer/browset

0b8142eee1d0f0a85120f3e43a32a3cda850bf19 — Zach DeCook 1 year, 1 month ago 03c758a
protocols: Support http/https
2 files changed, 16 insertions(+), 5 deletions(-)

M browset.py
A protocol/http.py
M browset.py => browset.py +11 -5
@@ 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])


A protocol/http.py => protocol/http.py +5 -0
@@ 0,0 1,5 @@
import requests
class HttpProtocol():
    def get(url):
        r = requests.get(url)
        return (r.headers['content-type'].split(';')[0], r)