about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-30 18:45:54 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-30 19:10:42 +0100
commit6131db458fc1d0f8faf17ded996ae25092af8900 (patch)
tree2f4276472fbe7abbdd6f42a00d4d0d5b86e3dfab
parent52aba81c301cb4db3a9c34ca2aa285c407d1d848 (diff)
downloadchawan-6131db458fc1d0f8faf17ded996ae25092af8900.tar.gz
about: move to loader
This means we can now use about:downloads for downloads.
Plus it shaves off some ks from the distribution.
-rw-r--r--Makefile12
-rw-r--r--adapter/protocol/about.nim20
-rw-r--r--doc/protocols.md53
-rw-r--r--res/urimethodmap1
-rw-r--r--src/local/pager.nim2
-rw-r--r--src/server/loader.nim18
6 files changed, 48 insertions, 58 deletions
diff --git a/Makefile b/Makefile
index ee4ba5f5..e406f057 100644
--- a/Makefile
+++ b/Makefile
@@ -61,7 +61,7 @@ endif
 all: $(OUTDIR_BIN)/cha $(OUTDIR_BIN)/mancha $(OUTDIR_CGI_BIN)/http \
 	$(OUTDIR_CGI_BIN)/gemini $(OUTDIR_LIBEXEC)/gmi2html \
 	$(OUTDIR_CGI_BIN)/gopher $(OUTDIR_LIBEXEC)/gopher2html \
-	$(OUTDIR_CGI_BIN)/finger $(OUTDIR_CGI_BIN)/about \
+	$(OUTDIR_CGI_BIN)/finger \
 	$(OUTDIR_CGI_BIN)/file $(OUTDIR_CGI_BIN)/ftp $(OUTDIR_CGI_BIN)/sftp \
 	$(OUTDIR_LIBEXEC)/dirlist2html $(OUTDIR_LIBEXEC)/uri2html \
 	$(OUTDIR_LIBEXEC)/img2html \
@@ -119,7 +119,6 @@ sandbox = src/utils/sandbox.nim $(chaseccomp)
 
 $(OUTDIR_CGI_BIN)/man: $(twtstr)
 $(OUTDIR_CGI_BIN)/http: adapter/protocol/curl.nim $(sandbox)
-$(OUTDIR_CGI_BIN)/about: res/chawan.html res/license.md
 $(OUTDIR_CGI_BIN)/file: $(twtstr)
 $(OUTDIR_CGI_BIN)/ftp: $(lcgi)
 $(OUTDIR_CGI_BIN)/sftp: $(lcgi) $(twtstr)
@@ -202,7 +201,7 @@ manpages = $(manpages1) $(manpages5) $(manpages7)
 .PHONY: manpage
 manpage: $(manpages:%=doc/%)
 
-protocols = http about file ftp sftp gopher gemini finger man spartan stbi \
+protocols = http file ftp sftp gopher gemini finger man spartan stbi \
 	jebp sixel canvas resize chabookmark nanosvg
 converters = gopher2html md2html ansi2html gmi2html dirlist2html uri2html img2html
 tools = urlenc nc
@@ -237,13 +236,14 @@ uninstall:
 	for f in $(protocols); do rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/$$f; done
 # notes:
 # * png has been removed in favor of stbi
-# * data has been moved back into the main binary
+# * data, about have been moved back into the main binary
 # * gmifetch has been replaced by gemini
 # * cha-finger has been renamed to finger
-	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/png
+	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/about
+	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/cha-finger
 	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/data
 	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/gmifetch
-	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/cha-finger
+	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/png
 	rmdir $(LIBEXECDIR_CHAWAN)/cgi-bin || true
 	for f in $(converters) $(tools); do rm -f $(LIBEXECDIR_CHAWAN)/$$f; done
 # urldec is just a symlink to urlenc
diff --git a/adapter/protocol/about.nim b/adapter/protocol/about.nim
deleted file mode 100644
index 4f6dc97b..00000000
--- a/adapter/protocol/about.nim
+++ /dev/null
@@ -1,20 +0,0 @@
-when NimMajor >= 2:
-  import std/envvars
-else:
-  import std/os
-
-const chawan = staticRead"res/chawan.html"
-const license = staticRead"res/license.md"
-
-template printPage(s, t: static string) =
-  stdout.write("Content-Type: " & t & "\n\n")
-  stdout.write(s)
-
-proc main() =
-  case getEnv("MAPPED_URI_PATH")
-  of "blank": printPage("", "text/plain")
-  of "chawan": printPage(chawan, "text/html")
-  of "license": printPage(license, "text/markdown")
-  else: stdout.write("Cha-Control: ConnectionError 4 about page not found")
-
-main()
diff --git a/doc/protocols.md b/doc/protocols.md
index e927d01e..9abb5265 100644
--- a/doc/protocols.md
+++ b/doc/protocols.md
@@ -120,10 +120,6 @@ wishes; see below).
 `file:` loads a file from the local filesystem. In case of directories, it
 shows the directory listing like the FTP protocol does.
 
-`about:` contains informational pages about the browser. At the time of
-writing, the following pages are available: `about:chawan`, `about:blank`
-and `about:license`.
-
 `man:`, `man-k:` and `man-l:` are wrappers around the commands `man`, `man -k`
 and `man -l`. These look up man pages using `/usr/bin/man` and turn on-page
 references into links. A wrapper command `mancha` also exists; this has an
@@ -132,37 +128,44 @@ it has been rewritten in Nim (and therefore no longer depends on Perl either).
 
 ## Internal schemes: cgi-bin:, stream:, cache:, data:
 
-Four internal protocols exist: `cgi-bin:`, `stream:`, `cache:` and `data:`.
-These are the basic building blocks for the implementation of every protocol
-mentioned above; for this reason, these can *not* be replaced, and are
-implemented in the main browser binary.
+Five internal protocols exist: `cgi-bin:`, `stream:`, `cache:`,
+`data:` and `about:`.  These are the basic building blocks for the
+implementation of every protocol mentioned above; for this reason, these
+can *not* be replaced, and are implemented in the main browser binary.
 
-`cgi-bin:` executes a local CGI script. This scheme is used for the actual
-implementation of the non-internal protocols mentioned above. Local CGI scripts
-can also be used to implement wrappers of other programs inside Chawan
-(e.g. dictionaries).
+`cgi-bin:` executes a local CGI script.  This scheme is used for the
+actual implementation of the non-internal protocols mentioned above.
+Local CGI scripts can also be used to implement wrappers of other
+programs inside Chawan (e.g. dictionaries).
 
-`stream:` is used for reading in streams returned by external programs or passed
-to Chawan via standard input. It differs from `cgi-bin:` in that it does not
-cooperate with the external process, and that the loader does not keep track
-of where the stream originally comes from. Therefore it is suitable for reading
-in the output of mailcap entries, or for turning stdin into a URL.
+`stream:` is used for streams returned by external programs.  It differs
+from `cgi-bin:` in that it does not cooperate with the external process,
+and that the loader does not keep track of where the stream originally
+comes from.  Therefore it is suitable for reading in the output of
+mailcap entries, or for turning stdin into a URL.
 
-Since Chawan does not keep track of the origin of `stream:` URLs, it is not
-possible to reload them. (For that matter, reloading stdin does not make much
-sense anyway.) To support rewinding and "view source", the output of `stream:`'s
-is stored in a temporary file until the buffer is discarded.
+It is not possible to reload `stream:` URLs.  To support rewinding and
+"view source", the output of `stream:`'s is stored in a cache file until
+the buffer is discarded.
 
 `cache:` is not something an end user would normally see; it's used for
-rewinding or re-interpreting streams already downloaded. Note that this is not a
-real cache; files are deterministically loaded from the "cache" upon certain
-actions, and from the network upon others, but neither is used as a fallback
-to the other.
+rewinding or re-interpreting streams already downloaded.
+
+Caching works differently than in most other browsers; files are
+deterministically loaded from the cache upon certain actions, and from
+the network upon others, but neither is used as a fallback to the other.
 
 `data:` decodes a data URL as defined in RFC 2397. This used to be a CGI module,
 but has been moved back into the loader process because these URLs can get
 so long that they no longer fit into the environment.
 
+`about:` is inside the loader to allow for an implementation of the
+download list panel.  It should be turned into a CGI module once the
+loader gets RPC capabilities.
+
+The following about pages are available: `about:chawan`, `about:blank`,
+`about:license`, `about:download`.
+
 ## Custom protocols
 
 Chawan is protocol-agnostic. This means that the `cha` binary itself does not
diff --git a/res/urimethodmap b/res/urimethodmap
index bb9b9901..e395e70f 100644
--- a/res/urimethodmap
+++ b/res/urimethodmap
@@ -4,7 +4,6 @@ http:			cgi-bin:http
 https:			cgi-bin:http
 finger:			cgi-bin:finger
 gemini:			cgi-bin:gemini
-about:			cgi-bin:about
 file:			cgi-bin:file
 ftp:			cgi-bin:ftp
 sftp:			cgi-bin:sftp
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 2132b6a2..d3382db9 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -2155,7 +2155,7 @@ proc saveTo(pager: Pager; data: LineDataDownload; path: string) =
     pager.loader.resume(data.outputId)
     data.stream.sclose()
     pager.lineData = nil
-    discard pager.gotoURL(newRequest(newURL("download:view").get),
+    discard pager.gotoURL(newRequest(newURL("about:downloads").get),
       history = false)
   else:
     pager.ask("Failed to save to " & path & ". Retry?").then(
diff --git a/src/server/loader.nim b/src/server/loader.nim
index 2faadd3a..b8eb0c55 100644
--- a/src/server/loader.nim
+++ b/src/server/loader.nim
@@ -1180,10 +1180,15 @@ proc parseDownloadActions(ctx: LoaderContext; s: string): seq[DownloadAction] =
   result.sort(proc(a, b: DownloadAction): int = return cmp(a.n, b.n),
     Descending)
 
-proc loadDownload(ctx: LoaderContext; handle: InputHandle; request: Request) =
+proc loadAbout(ctx: LoaderContext; handle: InputHandle; request: Request) =
   let url = request.url
   case url.pathname
-  of "view":
+  of "blank":
+    ctx.loadDataSend(handle, "", "text/html")
+  of "chawan":
+    const body = staticRead"res/chawan.html"
+    ctx.loadDataSend(handle, body, "text/html")
+  of "downloads":
     if request.httpMethod == hmPost:
       # OK/STOP/PAUSE/RESUME clicked
       if request.body.t != rbtString:
@@ -1200,7 +1205,7 @@ proc loadDownload(ctx: LoaderContext; handle: InputHandle; request: Request) =
 <body>
 <h1 align=center>Download List Panel</h1>
 <hr>
-<form method=POST action=download:view>
+<form method=POST action=about:downloads>
 <hr>
 <pre>
 """
@@ -1227,6 +1232,9 @@ proc loadDownload(ctx: LoaderContext; handle: InputHandle; request: Request) =
 </body>
 """
     ctx.loadDataSend(handle, body, "text/html")
+  of "license":
+    const body = staticRead"res/license.md"
+    ctx.loadDataSend(handle, body, "text/markdown")
   else:
     handle.rejectHandle(ceInvalidURL, "invalid download URL")
 
@@ -1265,8 +1273,8 @@ proc loadResource(ctx: LoaderContext; client: ClientHandle;
       handle.close()
     of "data":
       ctx.loadData(handle, request)
-    of "download":
-      ctx.loadDownload(handle, request)
+    of "about":
+      ctx.loadAbout(handle, request)
     else:
       prevurl = request.url
       case ctx.config.uriMethodMap.findAndRewrite(request.url)