From 5ab0ba40b8019dff5ce05faaf923eb1a6a160241 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi

Date: Fri, 16 Jun 2023 16:02:34 +0300

Subject: [PATCH 1/1] Process Gemini/Titan via a scheme handler; updated docs,

change log

IssueID #2


README.md | 7 ++

docs/api.rst | 8 +-

gmcapsule/init.py | 12 +-

gmcapsule/gemini.py | 261 +++++++++++++++++++++++++-----------------

4 files changed, 173 insertions(+), 115 deletions(-)

diff --git a/README.md b/README.md

index be0fcb5..0b1540a 100644

--- a/README.md

+++ b/README.md

@@ -23,6 +23,7 @@ Create the following service file and save it as _~/.config/systemd/user/gmcapsu

 [Service]

 Type=simple

 ExecStart=<YOUR-INSTALL-PATH>/gmcapsuled

 Restart=always

 Environment="PYTHONUNBUFFERED=1"

 StandardOutput=syslog

@@ -46,6 +47,12 @@ The log can be viewed via journalctl (or syslog):

Change log

+### v0.5

+* Extension modules can register new protocols in addition to the built-in Gemini and Titan.

+* SIGHUP causes the configuration file to be reloaded and workers to be restarted. The listening socket remains open, so the socket and TLS parameters cannot be changed.

+* API change: Extension modules get initialized separately in each worker thread. Instead of a Capsule, the extension module init method is passed a WorkerContext. Capsule is no longer available as global state.

v0.4

diff --git a/docs/api.rst b/docs/api.rst

index 41024fe..75db2ed 100644

--- a/docs/api.rst

+++ b/docs/api.rst

@@ -12,6 +12,7 @@ These classes and functions are available to extension modules by importing

Cache

gemini.Request

gemini.Identity

Classes

@@ -29,7 +30,7 @@ Capsule

 :members:

Cache


+-----

.. autoclass:: gmcapsule.Cache

 :members:

@@ -43,6 +44,11 @@ Identity

.. autoclass:: gmcapsule.gemini.Identity

 :members:

+WorkerContext

+-------------

+.. autoclass:: gmcapsule.WorkerContext

Functions


diff --git a/gmcapsule/init.py b/gmcapsule/init.py

index 7a98b98..ebbeeb5 100644

--- a/gmcapsule/init.py

+++ b/gmcapsule/init.py

@@ -419,16 +419,16 @@ Initialization

Each extension module is required to have an initialization function:

-.. py:function:: extmod.init(capsule)

+.. py:function:: extmod.init(context)

 Initialize the extension module.

 This is called once immediately after the extension has been loaded.

     configuration parameters, install caches, and register entry

Requests

@@ -481,13 +481,13 @@ import shlex

import subprocess

from pathlib import Path

-from .gemini import Server, Cache

+from .gemini import Server, Cache, WorkerContext

from .markdown import to_gemtext as markdown_to_gemtext

version = '0.5.0'

all = [

 'get_mime_type', 'markdown_to_gemtext'

]

diff --git a/gmcapsule/gemini.py b/gmcapsule/gemini.py

index a7026a0..4744387 100644

--- a/gmcapsule/gemini.py

+++ b/gmcapsule/gemini.py

@@ -304,6 +304,7 @@ class WorkerContext:

         for hostname in self.hostnames:

             self.entrypoints[proto][hostname] = []

     self.caches = []

     self.is_quiet = False

 def config(self):

@@ -344,6 +345,18 @@ class WorkerContext:

     """

     self.caches.append(cache)

 def add(self, path, entrypoint, hostname=None, protocol='gemini'):

     """

     Register a URL entry point.

@@ -470,16 +483,142 @@ class WorkerContext:

     raise GeminiError(50, 'Permanent failure')

+class RequestData:

+def handle_gemini_or_titan_request(request_data):

class Worker(threading.Thread):

 """Thread that handles incoming requests from clients."""

 def __init__(self, id, cfg, work_queue, shutdown_event):

     super().__init__()

     self.id = id

     self.cfg = cfg

     self.port = cfg.port()

     self.context = WorkerContext(self.cfg, shutdown_event)

     self.context.set_quiet(id > 0)

     self.jobs = work_queue

@@ -520,9 +659,6 @@ class Worker(threading.Thread):

     MAX_LEN = 1024

     MAX_RECV = MAX_LEN + 2  # includes terminator "\r\n"

     request = None

     incoming = safe_recv(stream, MAX_RECV)

     try:

@@ -547,117 +683,26 @@ class Worker(threading.Thread):

         return

     if not request or len(data) > MAX_RECV:

         return

     cl_cert = stream.get_peer_certificate()

     identity = Identity(cl_cert) if cl_cert else None

             return

_server_instance = None

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/gmcapsule/main/patch/5ab0ba40b8019dff5ce05faaf923eb1a6a160241.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
33.931529 milliseconds
Gemini-to-HTML Time
4.282659 milliseconds

This content has been proxied by September (ba2dc).