Re: [dev] running a shortlink provider

From: Santtu Lakkala <>
Date: Wed, 31 May 2023 12:44:14 +0300


On 25.5.2023 6.47, Spenser Truex wrote:
> My internet friends and I have been wanting a shortlinks provider. How
> can I do this in a suckless way? I'd like to be able to host the
> shortlinks provider and easily let my friends point their own domains at
> my VPS.
> I used to just upload a HTML file with a redirect to the desired
> location in my webserver root. This doesn't work for a shared service
> though.
> There are a lot of bloated projects that I've found. Any suggestions?

Out of curiosity, I wrote a reasonably suckless PoC version[0] with C
and CGI, tested it to work with OpenBSD httpd and slowcgi.

It uses symbolic links in a directory as a data backend. This should not
have any race issues, as link creation should be an atomic operation.
Note that the default is to have 4 character tokens, that are randomly
generated, so expect collisions if you have a lot of links to shorten.

Every GET request is expected to be a redirection request, and every
POST is a link addition. GETs are identified by PATH_INFO, POST data can
have a token variable to use pre-specified text (if available), in
addition to the mandatory uri, successful addition returns the token
part as text/plain (i.e. not a full address).

Error reporting is minimal, but errors probably are handled.

I have no plans to implement this further, so consider this abandoned
from the get go; I can add patches if someone uncovers some of the
gaping holes there must be somewhere.

If someone should want to test it, and the non-existent documentation is
too sparse, please contact me directly, no reason to pollute the list.



Received on Wed May 31 2023 - 11:44:14 CEST

This archive was generated by hypermail 2.3.0 : Wed May 31 2023 - 13:36:09 CEST