MCPcopy Create free account
hub / github.com/erpc/erpc / gzipHandler

Function gzipHandler

erpc/http_server.go:1757–1780  ·  view source on GitHub ↗
(next http.Handler)

Source from the content-addressed store, hash-verified

1755}
1756
1757func gzipHandler(next http.Handler) http.Handler {
1758 // Pool writers across responses for better performance
1759 var gzPool = util.NewGzipWriterPool()
1760
1761 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1762 // Check if client accepts gzip encoding
1763 if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
1764 next.ServeHTTP(w, r)
1765 return
1766 }
1767
1768 // Create conditional gzip response writer that decides on first write
1769 gzw := &conditionalGzipWriter{
1770 ResponseWriter: w,
1771 pool: gzPool,
1772 }
1773
1774 // Call the next handler with our conditional gzip response writer
1775 next.ServeHTTP(gzw, r)
1776
1777 // Ensure proper cleanup
1778 _ = gzw.Close()
1779 })
1780}
1781
1782// resolveRealClientIP determines the originating client IP, honoring standard forwarding headers
1783// only when the immediate peer is a trusted forwarder. Falls back to remote address.

Callers 1

NewHttpServerFunction · 0.85

Calls 4

CloseMethod · 0.95
NewGzipWriterPoolFunction · 0.92
ServeHTTPMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected