MCPcopy
hub / github.com/tdewolff/minify / Middleware

Method Middleware

minify.go:365–371  ·  view source on GitHub ↗

Middleware provides a middleware function that minifies content on the fly by intercepting writes to http.ResponseWriter. http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ... Minification might be slower than just sending the original file! Caching is advised.

(next http.Handler)

Source from the content-addressed store, hash-verified

363// http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ...
364// Minification might be slower than just sending the original file! Caching is advised.
365func (m *M) Middleware(next http.Handler) http.Handler {
366 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
367 mw := m.ResponseWriter(w, r)
368 next.ServeHTTP(mw, r)
369 mw.Close()
370 })
371}
372
373// MiddlewareWithError provides a middleware function that minifies content on the fly by intercepting writes to http.ResponseWriter. The error function allows handling minification errors.
374// http.ResponseWriter loses all functionality such as Pusher, Hijacker, Flusher, ...

Callers 1

TestMiddlewareFunction · 0.80

Calls 2

ResponseWriterMethod · 0.95
CloseMethod · 0.45

Tested by 1

TestMiddlewareFunction · 0.64