tproxy

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	HeaderXProxyClientIP = "X-Proxy-ClientIP"
	HeaderXProxyToken    = "X-Proxy-Token" // #nosec G101
	HeaderXProxyTime     = "X-Proxy-Time"
	HeaderXProxyPass     = "X-Proxy-Pass"
)

Variables

This section is empty.

Functions

func GetClientIP

func GetClientIP(c fiber.Ctx) string

GetClientIP 获取客户端 IP 1. 上下文存储中获取 2. 下游代理头: 令牌仍是 HashString(xip, xtime, WebTokenSalt), 且 xtime 落在 SignTTL 闭区间内 3. TCP 协议 RemoteIP(), 空则 0.0.0.0 immutable

func ProxyHandler

func ProxyHandler(backendServers []string, timeout time.Duration, backendHost string) fiber.Handler

ProxyHandler 为管理员配置的固定可信 HTTP(S) 上游创建代理.

支持 IPv4/IPv6 和私网上游, 不使用 Fiber 全局目标限制策略; backendServers 不得 来自客户端请求. 裸 host:port 仍按 HTTP 处理, 无显式端口时使用协议默认端口. backendHost 为空时保留原请求 Host, 非空时使用构造期快照; 查询串保留原始编码. 路径沿用 Fiber 的路由规范化与默认安全检查, 歧义斜杠及 Fiber 无法确认自定义 client 保留的编码会返回 400. 空列表、无法解析的 URL、非 HTTP(S) 或缺主机在构造时 panic. 拨号和传输错误清空残留响应后返回原错误, 由调用方决定状态码和回包格式. HTTPS 保持证书校验, 不跟随上游重定向.

示例:

backendHost := "upstream.example:8080"
backendServers := []string{"http://upstream.example:8080"}
proxyHandler := ProxyHandler(backendServers, 1*time.Second, backendHost)
app.Use("/es/", proxyHandler)

func SetClientIP

func SetClientIP(c fiber.Ctx)

SetClientIP 首个代理加密客户端 IP, 中间代理透传 当前来访为内网 IP 会跳过设置 immutable

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL