- 新增 IsInternalRedirect 检测内部重定向请求 - static handler 支持 internal 访问限制 - proxy handler 支持 internal 访问限制 - 支持 X-Accel-Redirect 内部重定向 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
29 lines
750 B
Go
29 lines
750 B
Go
package utils
|
|
|
|
import "github.com/valyala/fasthttp"
|
|
|
|
const (
|
|
// InternalRedirectKey 内部重定向标记
|
|
InternalRedirectKey = "__internal_redirect__"
|
|
)
|
|
|
|
// SetInternalRedirect 标记请求为内部重定向
|
|
func SetInternalRedirect(ctx *fasthttp.RequestCtx, targetPath string) {
|
|
ctx.SetUserValue(InternalRedirectKey, targetPath)
|
|
}
|
|
|
|
// IsInternalRedirect 检查是否为内部重定向
|
|
func IsInternalRedirect(ctx *fasthttp.RequestCtx) bool {
|
|
return ctx.UserValue(InternalRedirectKey) != nil
|
|
}
|
|
|
|
// GetInternalRedirectPath 获取内部重定向目标路径
|
|
func GetInternalRedirectPath(ctx *fasthttp.RequestCtx) string {
|
|
if v := ctx.UserValue(InternalRedirectKey); v != nil {
|
|
if path, ok := v.(string); ok {
|
|
return path
|
|
}
|
|
}
|
|
return ""
|
|
}
|