🐛 Bug fixes infinite redirecting
Some checks are pending
release-nightly / build-docker (push) Waiting to run

This commit is contained in:
LittleSheep 2024-01-26 16:04:34 +08:00
parent 302491741f
commit 2860542e44
3 changed files with 17 additions and 16 deletions

View File

@ -1,12 +1,12 @@
id = "example-region" id = "example-region"
[[locations]] # [[locations]]
id = "example-websocket" # id = "example-websocket"
host = ["localhost:8000"] # host = ["localhost:8000"]
path = ["/ws"] # path = ["/ws"]
[[locations.destinations]] # [[locations.destinations]]
id = "example-websocket-destination" # id = "example-websocket-destination"
uri = "http://localhost:8765" # uri = "http://localhost:8765"
# [[locations]] # [[locations]]
# id = "example-warden" # id = "example-warden"
@ -23,9 +23,9 @@ uri = "http://localhost:8765"
# environment = ["PUBLIC_CMS=https://smartsheep.studio"] # environment = ["PUBLIC_CMS=https://smartsheep.studio"]
[[locations]] [[locations]]
id = "example-static" id = "example"
host = ["localhost:8000"] host = ["localhost:8000"]
path = ["/"] path = ["/"]
[[locations.destinations]] [[locations.destinations]]
id = "example-static-destination" id = "example-destination"
uri = "files://test/data" uri = "http://protocol.smartsheep.studio:20004"

View File

@ -9,7 +9,6 @@ import (
"github.com/gofiber/fiber/v2/utils" "github.com/gofiber/fiber/v2/utils"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/spf13/viper"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
"io/fs" "io/fs"
"net/http" "net/http"
@ -32,10 +31,11 @@ func makeUnifiedResponse(c *fiber.Ctx, dest *Destination) error {
} }
func makeHypertextResponse(c *fiber.Ctx, dest *Destination) error { func makeHypertextResponse(c *fiber.Ctx, dest *Destination) error {
timeout := time.Duration(viper.GetInt64("performance.network_timeout")) * time.Millisecond limit := 60 * time.Millisecond
return proxy.Do(c, dest.MakeUri(c), &fasthttp.Client{ uri := dest.MakeUri(c)
ReadTimeout: timeout, return proxy.Do(c, uri, &fasthttp.Client{
WriteTimeout: timeout, ReadTimeout: limit,
WriteTimeout: limit,
}) })
} }

View File

@ -75,9 +75,10 @@ func (v *Destination) MakeUri(ctx *fiber.Ctx) string {
path := string(ctx.Request().URI().Path()) path := string(ctx.Request().URI().Path())
hash := string(ctx.Request().URI().Hash()) hash := string(ctx.Request().URI().Hash())
protocol := v.GetProtocol()
uri, _ := v.GetRawUri() uri, _ := v.GetRawUri()
return uri + path + return protocol + "://" + uri + path +
lo.Ternary(len(queries) > 0, "?"+strings.Join(queries, "&"), "") + lo.Ternary(len(queries) > 0, "?"+strings.Join(queries, "&"), "") +
lo.Ternary(len(hash) > 0, "#"+hash, "") lo.Ternary(len(hash) > 0, "#"+hash, "")
} }