Skip to content

Commit

Permalink
✨ Skip etag for the api
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Feb 24, 2024
1 parent fd37d7f commit e86a70b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 78 deletions.
25 changes: 24 additions & 1 deletion pkg/cmds/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package server

import (
"context"
"crypto/sha256"
"hash"
"hash/crc32"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -84,7 +87,27 @@ func Serve(serverConfig ServerConfig) error {
config := ptr.To(configs.GetConfiguration())

e.Use(middleware.CORS())
e.Use(middlewares.Etag())
e.Use(middlewares.WithEtagConfig(middlewares.EtagConfig{
Skipper: func(c echo.Context) bool {
reqPath := c.Request().URL.Path
if strings.HasPrefix(reqPath, "/api/v1/") {
return true
}
if strings.HasPrefix(reqPath, "/v2/") {
return true
}
return false

Check warning on line 99 in pkg/cmds/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmds/server/server.go#L90-L99

Added lines #L90 - L99 were not covered by tests
},
Weak: true,
HashFn: func(config middlewares.EtagConfig) hash.Hash {
if config.Weak {
const crcPol = 0xD5828281
crc32qTable := crc32.MakeTable(crcPol)
return crc32.New(crc32qTable)
}
return sha256.New()

Check warning on line 108 in pkg/cmds/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmds/server/server.go#L102-L108

Added lines #L102 - L108 were not covered by tests
},
}))
e.Use(echoprometheus.NewMiddleware(consts.AppName))
e.GET("/metrics", echoprometheus.NewHandler())
e.Use(middlewares.Healthz())
Expand Down
34 changes: 0 additions & 34 deletions scripts/offline-package.sh

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/samples/restart.sh

This file was deleted.

28 changes: 0 additions & 28 deletions scripts/samples/start.sh

This file was deleted.

0 comments on commit e86a70b

Please sign in to comment.