(next http.Handler)
| 1755 | } |
| 1756 | |
| 1757 | func 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. |
no test coverage detected