fixed gzip middleware not applying when serving static files

This commit is contained in:
Gani Georgiev 2024-11-28 13:49:32 +02:00
parent d92016af81
commit ab7194a639
2 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,9 @@
## v0.23.3 (WIP)
- Fixed Gzip middleware not applying when serving static files.
## v0.23.2 ## v0.23.2
- Fixed `RecordQuery()` custom struct scanning ([#5958](https://github.com/pocketbase/pocketbase/discussions/5958)). - Fixed `RecordQuery()` custom struct scanning ([#5958](https://github.com/pocketbase/pocketbase/discussions/5958)).

View File

@ -221,23 +221,26 @@ func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error {
} }
} }
func (w *gzipResponseWriter) ReadFrom(r io.Reader) (n int64, err error) { // Note: Disable the implementation for now because in case the platform
if w.wroteHeader { // supports the sendfile fast-path it won't run gzipResponseWriter.Write,
w.ResponseWriter.WriteHeader(w.code) // preventing compression on the fly.
} //
// func (w *gzipResponseWriter) ReadFrom(r io.Reader) (n int64, err error) {
rw := w.ResponseWriter // if w.wroteHeader {
for { // w.ResponseWriter.WriteHeader(w.code)
switch rf := rw.(type) { // }
case io.ReaderFrom: // rw := w.ResponseWriter
return rf.ReadFrom(r) // for {
case router.RWUnwrapper: // switch rf := rw.(type) {
rw = rf.Unwrap() // case io.ReaderFrom:
default: // return rf.ReadFrom(r)
return io.Copy(w.ResponseWriter, r) // case router.RWUnwrapper:
} // rw = rf.Unwrap()
} // default:
} // return io.Copy(w.ResponseWriter, r)
// }
// }
// }
func (w *gzipResponseWriter) Unwrap() http.ResponseWriter { func (w *gzipResponseWriter) Unwrap() http.ResponseWriter {
return w.ResponseWriter return w.ResponseWriter