Gabbro 0.1.2 Release

Here's what I've been up to these couple of days

Directory listing

Imagine you have a gemlog that resides in "./root/gemlog/" with entries like:

gemlog:
	subdir:
		page-a1.gmi
		page-a2.gmi
	page1.gmi
	page2.gmi
	...
	page128.gmi

To see all of them and be able to select the one you're interested in you'd have to write an index and put it into that directory. Even having it being generated is pretty annoying, right?

What if we could just ask for the directory content as "mydomagin.org/gemlog" and get this in response:

=> /subdir [dir] subdir
=> /page1.gmi [page] page1
// blabla
=> /page128.gmi [page] page128

That seems pretty easy to implement server-side and have it serve us directory contents like that, as if it was an FTP of some sorts. However, it comes with some security drawbacks.

What if your directory structire looked like that:

content:
	secrets:
		cert.pem
		key.pem
	gemlog:
		subdir:
			page-a1.gmi
			page-a2.gmi
		page1.gmi
		page2.gmi
		...
		page128.gmi

And then someone sneaky asked for "/content/secrets" with a lucky guess or bruteforcing? "/content/gemlog" is a valid request and should be listed, but "/content/secrets" should be protected. We shouldn't even give away the fact that it exists in the first place by responding with NotFound instead of PermissionDenied status.

Well now we can achieve all of that with a config:

Config

[display]
dir_label = "📁"  # folder emoji
page_label = "📝" # memo emoji

[listing]
enable_listing = true
allowed_dirs = ["./root/content/gemlog"]

First section configures how directories and files will be displayed. In the example above I used [dir] and [file], but it really can be anything we want, even emojis. Lagrange renders them pretty nicely btw, replacing => in the links with emojis if they're the first symbols in the link's text.

Second one tells the server if the listing functionality is enabled, and what directories are allowed to be listed, including their subdirectories. I haven't yet implemented subdir exclusion roles because it's pretty annoying to code and overcomplicates the whole thing, so I don't think it's really necessary.

Here's how it looks in Lagrange [pic]:

0-1-2-pic.png

Mime

Nothing fancy here, but now Gabbro tries to guess mime type of a file and put it into "meta" field of the response. .gmi/gemini should be now served as text/gemini. Not like anyone cares about mime types, gemini protocol works pretty fine without them anyway :D

Tests

I also somewhat improved tests coverage for basic requests, directories traversal, listing, mime and all other stuff. Gabbro now may be one of the most (if not THE most) thoroughly tested server for gemini 🎉

Too bad I can't yet make sourcehut to run them automatically on commits, but I think we'll get there someday :)

merge commit on sourcehut

That's all for now. I'm pretty excited about how well the project goes. It already does so much and still is less than 1k lines of code! 676 to be precise. Also this capsule now is run by 0.1.2 and you can check out the listing functionality with this link:

back