Skip to content

Commit

Permalink
fix retry when it is a live forever-lived http request
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Jan 6, 2024
1 parent 15b3ca5 commit 4c5f009
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewConfig() *Config {
proxyConfig := middleware.ProxyConfig{
Skipper: middleware.DefaultSkipper,
ContextKey: "target",
RetryCount: 0,
RetryCount: len(configFile.TezosHost) + 1,
Balancer: balancer,
RetryFilter: func(c echo.Context, err error) bool {
if httpErr, ok := err.(*echo.HTTPError); ok {
Expand Down
1 change: 0 additions & 1 deletion config/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func initViper() *ConfigFile {


// Set the configuration file name and path
viper.SetConfigName("tzproxy")
viper.SetConfigType("yaml")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/fraidev/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/marigold-dev/tzproxy/middlewares"
"github.com/marigold-dev/tzproxy/config"
"github.com/marigold-dev/tzproxy/middlewares"
"github.com/ziflex/lecho/v3"
)

Expand Down
5 changes: 4 additions & 1 deletion middlewares/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func Cache(config *config.Config) echo.MiddlewareFunc {
return echocache.New(&echocache.Config{
TTL: config.CacheTTL,
Cache: func(r *http.Request) bool {
if !config.ConfigFile.Cache.Enabled || r.Method != http.MethodGet {
if !config.ConfigFile.Cache.Enabled ||
r.Method != http.MethodGet ||
strings.Contains(r.URL.Path, "mempool") ||
strings.Contains(r.URL.Path, "monitor") {
return false
}

Expand Down
6 changes: 5 additions & 1 deletion middlewares/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package middlewares
import (
"bytes"
"net/http"
"strings"

"github.com/labstack/echo/v4"
"github.com/marigold-dev/tzproxy/config"
Expand All @@ -11,7 +12,10 @@ import (
func Retry(config *config.Config) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
if config.ConfigFile.TezosHostRetry == "" {
if config.ConfigFile.TezosHostRetry == "" ||
c.Request().Method != http.MethodGet ||
strings.Contains(c.Request().URL.Path, "mempool") ||
strings.Contains(c.Request().URL.Path, "monitor") {
return next(c)
}

Expand Down

0 comments on commit 4c5f009

Please sign in to comment.