Skip to content

[Audit] fiber: /compression bypasses Fiber built-in compression middleware #221

@jerrythetruckdriver

Description

@jerrythetruckdriver

Rule violated

@Kaliumhexacyanoferrat

Use framework-level APIs — "If a framework provides a documented, high-level way to accomplish a task, the benchmark implementation must use it."

Details

Fiber provides a well-documented compression middleware at github.com/gofiber/fiber/v2/middleware/compress. The implementation ignores it entirely and hand-rolls compression using Go stdlib compress/flate and compress/gzip:

File: frameworks/fiber/main.go, /compression handler (~line 155)

ae := c.Get("Accept-Encoding")
if strings.Contains(ae, "deflate") {
    c.Set("Content-Encoding", "deflate")
    w, err := flate.NewWriter(c.Response().BodyWriter(), flate.BestSpeed)
    // ...
} else if strings.Contains(ae, "gzip") {
    c.Set("Content-Encoding", "gzip")
    w, err := gzip.NewWriterLevel(c.Response().BodyWriter(), gzip.BestSpeed)
    // ...
}

The framework middleware handles Accept-Encoding negotiation, content-encoding headers, and compression level configuration. Bypassing it means the benchmark no longer measures Fiber's compression — it measures Go's stdlib compressors with Fiber's routing on top.

Suggested fix

Use Fiber's built-in middleware:

import "github.com/gofiber/fiber/v2/middleware/compress"

app.Use("/compression", compress.New(compress.Config{
    Level: compress.LevelBestSpeed,
}))

app.Get("/compression", func(c *fiber.Ctx) error {
    c.Set("Server", "fiber")
    c.Set("Content-Type", "application/json")
    return c.Send(jsonLargeResponse)
})

This keeps the measurement honest — users want to know how Fiber's compression performs, not how stdlib performs behind Fiber's router.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions