fix(echo): use built-in compression middleware instead of manual gzip/deflate#231
Conversation
…zip/deflate Replace hand-rolled compress/gzip and compress/flate writers in the /compression endpoint with Echo's built-in middleware.GzipWithConfig() registered globally at level 1. This matches the framework-level API rule — Echo provides a documented gzip middleware, so we use it. The middleware handles Accept-Encoding negotiation automatically. For non-compression endpoints, the middleware short-circuits when no Accept-Encoding header is present. Fixes MDA2AV#229
Echo v4.15.1 middleware imports golang.org/x/time/rate (for rate_limiter.go), but the go.sum was missing the entry. Run go mod tidy to fix.
|
[test] db endpoint (mixed test prerequisite) |
Global gzip middleware was interfering with Content-Type headers on /db, /static, and /async-db endpoints, causing them to return text/html instead of application/json and text/css. Apply gzip as route-level middleware on /compression only.
|
Good catch — the global gzip middleware was messing with Content-Type on all routes. Scoped it to just |
|
CI failed but it's a runner network issue — |
|
/benchmark compression |
|
🚀 Benchmark run triggered for |
Benchmark ResultsFramework: Full log |
|
CI passes now ✅ and compression benchmark looks solid — 8.8K req/s at 4096c, 8.3K at 16384c. Consistent with the other Go frameworks doing per-request gzip at level 1. The built-in middleware is doing its job correctly now. Ready for merge whenever you're happy with it! |
Replaces hand-rolled gzip/deflate handling with Echo's built-in
middleware.GzipWithConfig().What changed:
compress/gzipandcompress/flatewriter setupmiddleware.GzipWithConfig(middleware.GzipConfig{Level: 1})— same level 1 approach as other framework entriesWhy:
Same pattern as the Fiber fix (#222 / issue #221). The Echo entry was bypassing the framework's own compression middleware with manual gzip/deflate handling, which isn't how you'd use Echo in production.
Note: Echo's built-in middleware only supports gzip (not deflate). Since gcannon sends
Accept-Encoding: gzip, deflateand gzip takes priority, this has no impact on benchmark results.Fixes #229.
(Reopened from #230 — needed to push go.sum fix from fork due to branch protection)