[feat] Use Accept-Encoding to allow data compression #755
Labels
No labels
approved, awaiting change
broken setup
bug
cannot reproduce
configuration
documentation
duplicate
enhancement
extremely low priority
feature request
Fix it yourself
help wanted
invalid
mastodon_api
needs change/feedback
needs docs
needs tests
not a bug
not our bug
planned
pleroma_api
privacy
question
static_fe
triage
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
AkkomaGang/akkoma#755
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The idea
As a webmaster, I see Akkoma in my logs and see it does not use data compression (accept-encoding header). All modern HTTP clients support this feature, so it is common to also support this on the server side.
In our case we recently decided to block all requests with HTTP/1.0 and those that are not offering to use data encoding. Due to that, we saw a few RSS feed readers showing up, and Akkoma.
Example from log (ip and instance masked), the 426 error means it is blocked:
2024-04-21T20:24:21+00:00 426 1.2.3.4 "GET /cheat-sheets/curl/ HTTP/1.1" 16 "-" "Akkoma 3.12.2; https://masked <masked>" TLSv1.3/TLS_AES_256_GCM_SHA384 0.000 .I did a quick look in the code, but as I'm not familiar with it, I couldn't find the HTTP handler.
My suggestion would be to enable at least Gzip, but preferably Brotli (better savings) and possibly zstd (not as common, yet).
Thanks for your consideration!
The reasoning
Save data traffic, which is beneficial for everyone involved (data centers, publishers, and clients). Especially as this involves every single HTTP request the software performs, it will add up over time considering that on a HTML/CSS/SVG/JS often the savings are great.
Have you searched for this feature request?
In theory this should be as easy as adding
Tesla.Middleware.DecompressResponsenear the end of our Tesla middleware list exepct forHEADrequests (only followed by the telemetry middleware). However, the middleware is buggy in the Tesla version we currently use and crashes on responses with an empty body like below. A fix was already merged upstream and is included in the latest Tesla release though.Note: in practice, the vast majority of data we receive or send will be ActivityPub documents to/from inboxes which cannot/will not be compressed either way. It certainly would be nice to use transport compression for rich media (link preview) requests though
EDIT: but even with the fix, the middleware currently always deletes the
Content-encodingheader, not sure if that might cause problems (other than for HEAD requests where we want to omit the middleware for other related reasons anyway)The decompression middleware got some more fixes merged; after the next Tesla release (> 1.15.3) I think we should be able to make use of it