copyparty/bin/handlers
2025-02-19 22:41:30 +00:00
..
caching-proxy.py 404/403 can be handled with plugins 2023-07-07 21:33:40 +00:00
ip-ok.py 404/403 can be handled with plugins 2023-07-07 21:33:40 +00:00
never404.py 404/403 can be handled with plugins 2023-07-07 21:33:40 +00:00
nooo.py 404/403 can be handled with plugins 2023-07-07 21:33:40 +00:00
randpic.py new example: randpic.py 2025-02-19 22:41:30 +00:00
README.md new example: randpic.py 2025-02-19 22:41:30 +00:00
redirect.py handlers: add http-redirect example 2025-02-07 19:03:13 +00:00
sorry.py 404/403 can be handled with plugins 2023-07-07 21:33:40 +00:00

replace the standard 404 / 403 responses with plugins

usage

load plugins either globally with --on404 ~/dev/copyparty/bin/handlers/sorry.py or for a specific volume with :c,on404=~/handlers/sorry.py

api

each plugin must define a main() which takes 3 arguments;

  • cli is an instance of copyparty/httpcli.py (the monstrosity itself)
  • vn is the VFS which overlaps with the requested URL, and
  • rem is the URL remainder below the VFS mountpoint
    • so vn.vpath + rem == cli.vpath == original request

examples

on404

  • redirect.py sends an HTTP 301 or 302, redirecting the client to another page/file
  • randpic.py redirects /foo/bar/randpic.jpg to a random pic in /foo/bar/
  • sorry.py replies with a custom message instead of the usual 404
  • nooo.py replies with an endless noooooooooooooo
  • never404.py 100% guarantee that 404 will never be a thing again as it automatically creates dummy files whenever necessary
  • caching-proxy.py transforms copyparty into a squid/varnish knockoff

on403

  • ip-ok.py disables security checks if client-ip is 1.2.3.4

notes

  • on403 only works for trivial stuff (basic http access) since I haven't been able to think of any good usecases for it (was just easy to add while doing on404)