Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Feb 21, 2024
1 parent bbdeff8 commit 1d133df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.19.x, 1.20.x, 1.21.x]
go-version: [1.19.x, 1.20.x, 1.21.x, 1.22.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
42 changes: 24 additions & 18 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,15 +1038,16 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {
fileEncoding := ""
byteRange := ctx.Request.Header.peek(strRange)
if len(byteRange) == 0 && h.compress {
if h.compressBrotli && ctx.Request.Header.HasAcceptEncodingBytes(strBr) {
switch {
case h.compressBrotli && ctx.Request.Header.HasAcceptEncodingBytes(strBr):
mustCompress = true
fileCacheKind = brotliCacheKind
fileEncoding = "br"
} else if ctx.Request.Header.HasAcceptEncodingBytes(strGzip) {
case ctx.Request.Header.HasAcceptEncodingBytes(strGzip):
mustCompress = true
fileCacheKind = gzipCacheKind
fileEncoding = "gzip"
} else if ctx.Request.Header.HasAcceptEncodingBytes(strZstd) {
case ctx.Request.Header.HasAcceptEncodingBytes(strZstd):
mustCompress = true
fileCacheKind = zstdCacheKind
fileEncoding = "zstd"
Expand Down Expand Up @@ -1107,11 +1108,12 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {

hdr := &ctx.Response.Header
if ff.compressed {
if fileEncoding == "br" {
switch fileEncoding {
case "br":
hdr.SetContentEncodingBytes(strBr)
} else if fileEncoding == "gzip" {
case "gzip":
hdr.SetContentEncodingBytes(strGzip)
} else if fileEncoding == "zstd" {
case "zstd":
hdr.SetContentEncodingBytes(strZstd)
}
}
Expand Down Expand Up @@ -1316,11 +1318,12 @@ nestedContinue:

if mustCompress {
var zbuf bytebufferpool.ByteBuffer
if fileEncoding == "br" {
switch fileEncoding {
case "br":
zbuf.B = AppendBrotliBytesLevel(zbuf.B, w.B, CompressDefaultCompression)
} else if fileEncoding == "gzip" {
case "gzip":
zbuf.B = AppendGzipBytesLevel(zbuf.B, w.B, CompressDefaultCompression)
} else if fileEncoding == "zstd" {
case "zstd":
zbuf.B = AppendZstdBytesLevel(zbuf.B, w.B, CompressZstdDefault)
}
w = &zbuf
Expand Down Expand Up @@ -1420,21 +1423,22 @@ func (h *fsHandler) compressFileNolock(
}
return nil, errNoCreatePermission
}
if fileEncoding == "br" {
switch fileEncoding {
case "br":
zw := acquireStacklessBrotliWriter(zf, CompressDefaultCompression)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
err = err1
}
releaseStacklessBrotliWriter(zw, CompressDefaultCompression)
} else if fileEncoding == "gzip" {
case "gzip":
zw := acquireStacklessGzipWriter(zf, CompressDefaultCompression)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
err = err1
}
releaseStacklessGzipWriter(zw, CompressDefaultCompression)
} else if fileEncoding == "zstd" {
case "zstd":
zw := acquireStacklessZstdWriter(zf, CompressZstdDefault)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
Expand Down Expand Up @@ -1464,21 +1468,22 @@ func (h *fsHandler) newCompressedFSFileCache(f fs.File, fileInfo fs.FileInfo, fi
err error
)

if fileEncoding == "br" {
switch fileEncoding {
case "br":
zw := acquireStacklessBrotliWriter(w, CompressDefaultCompression)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
err = err1
}
releaseStacklessBrotliWriter(zw, CompressDefaultCompression)
} else if fileEncoding == "gzip" {
case "gzip":
zw := acquireStacklessGzipWriter(w, CompressDefaultCompression)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
err = err1
}
releaseStacklessGzipWriter(zw, CompressDefaultCompression)
} else if fileEncoding == "zstd" {
case "zstd":
zw := acquireStacklessZstdWriter(w, CompressZstdDefault)
_, err = copyZeroAlloc(zw, f)
if err1 := zw.Flush(); err == nil {
Expand Down Expand Up @@ -1634,17 +1639,18 @@ func readFileHeader(f io.Reader, compressed bool, fileEncoding string) ([]byte,
)
if compressed {
var err error
if fileEncoding == "br" {
switch fileEncoding {
case "br":
if br, err = acquireBrotliReader(f); err != nil {
return nil, err
}
r = br
} else if fileEncoding == "gzip" {
case "gzip":
if zr, err = acquireGzipReader(f); err != nil {
return nil, err
}
r = zr
} else if fileEncoding == "zstd" {
case "zstd":
if zsr, err = acquireZstdReader(f); err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/klauspost/compress/zstd"
"github.com/valyala/bytebufferpool"

"github.com/valyala/fasthttp/stackless"
)

Expand Down
2 changes: 1 addition & 1 deletion zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func testZstdBytesSingleCase(s string) error {
if !bytes.Equal(ZstdpedS[:len(prefix)], prefix) {
return fmt.Errorf("unexpected prefix when compressing %q: %q. Expecting %q", s, ZstdpedS[:len(prefix)], prefix)
}

unZstdedS, err := AppendUnzstdBytes(prefix, ZstdpedS[len(prefix):])
if err != nil {
return fmt.Errorf("unexpected error when uncompressing %q: %w", s, err)
Expand Down

0 comments on commit 1d133df

Please sign in to comment.