Skip to content

Instantly share code, notes, and snippets.

@TobiX
Last active April 24, 2024 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TobiX/9daa43186bcd80071fcfe726f91c9bc6 to your computer and use it in GitHub Desktop.
Save TobiX/9daa43186bcd80071fcfe726f91c9bc6 to your computer and use it in GitHub Desktop.
Caddy Tar Pit

This is a silly snippet of caddy config file to send heavily compressed huge files to clients prodding "stupid" URLs. (idea from https://tech.lgbt/@becomethewaifu/111879788755441482)

This needs a directory with 3 precompressed files, which may be created like this (tune numbers if you have more/less bandwith to spare or want to annoy "visitors" more/less):

dd if=/dev/zero bs=1M count=10240 status=progress | gzip -9 > 42.gzip
dd if=/dev/zero bs=1M count=102400 status=progress | brotli > 42.br
dd if=/dev/zero bs=1M count=102400 status=progress | zstd -9 -T0 > 42.zstd

I got these compression ratios:

File Compressed Uncompressed
42.gzip 9.937 MiB 10 GiB
42.br 82.032 KiB 100 GiB
42.zstd 3.17 MiB 100 GiB
# Tar pit
@shit {
path */.env
path /wp-login.php
}
handle @shit {
root * /srv/www
vars compression gzip
@is_br header Accept-Encoding *br*
vars @is_br compression br
@is_zstd header Accept-Encoding *zstd*
vars @is_zstd compression zstd
header {
Content-Encoding {vars.compression}
Content-Type "text/html; charset=utf-8"
}
rewrite * /42.{vars.compression}
file_server
}
@sussycatgirl
Copy link

Since the commands to create the compressed files can take quite a while to run, I'd recommend adding status=progress to the dd command so you actually see how far it is :3

@TobiX
Copy link
Author

TobiX commented Apr 24, 2024

@sussycatgirl Updated. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment