forwarded

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: MIT Imports: 1 Imported by: 1

README

Forwarded 转发请求原始信息接口

一个获取被转发请求的原始信息的接口

功能

  • 获取请求原始IP地址
  • 获取请求原始协议
  • 获取请求原始域名信息
  • 通过设置token验证请求是否有效

配置说明

#TOML版本,其他版本可以根据对应格式配置
#是否启用
Enabled=true

#原始ip头,为空则该功能不起效
ForwardedForHeader=""

#原始Host头,为空则该功能不起效
ForwardedHostHeader=""

#原始协议头,为空则该功能不起效
ForwardedProtoHeader=""

#转发信息认证头,为空该功能不起效
ForwardedTokenHeader="forwardedtoken"
#转发信息认真值,转发信息认证头起效时,传入的请求的对应请求头的值必须和该值相等,不然是无效请求
ForwardedTokenValue="1234567890"

#失败状态码,默认为400
FailStatusCode=400

#degbu模式,启用后会将客户ip加载响应头的"X-Remote-Addr"字段内
Debug=false

使用方式

m:=&forwarded.Middleware{}
err=toml.Unmarshal(data,m)
app.Use(m)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	//Enabled if this middleware is enabled.
	Enabled bool
	//ForwardedForHeader request header name which stores real ip.
	//If set to empty string,this feature will be disabeld.
	ForwardedForHeader string
	//ForwardedHostHeader request header name which stores real host.
	//If set to empty string,this feature will be disabeld.
	ForwardedHostHeader string
	//ForwardedProtoHeader request header name which stores real proto.
	//If set to empty string,this feature will be disabeld.
	ForwardedProtoHeader string
	//ForwardedTokenHeader request header name which stores token.
	//If set to empty string,this feature will be disabeld.
	ForwardedTokenHeader string
	//ForwardedTokenValue value which request header must equal.
	ForwardedTokenValue string
	//FailErrorCode error code raised when forwarded token verification fail.
	FailStatusCode int
	//Debug debug mode.Echo client ip in header "X-Remote-Addr".
	Debug bool
	// contains filtered or unexported fields
}

Middleware main middleware struct.

func New

func New() *Middleware

New create new middleware

func (*Middleware) DefaultTokenFailedAction

func (m *Middleware) DefaultTokenFailedAction(w http.ResponseWriter, r *http.Request)

DefaultTokenFailedAction return default token failed action

func (*Middleware) ServeMiddleware

func (m *Middleware) ServeMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeMiddleware return middleware.

func (*Middleware) SetTokenFailedAction

func (m *Middleware) SetTokenFailedAction(action func(w http.ResponseWriter, r *http.Request))

SetTokenFailedAction set action which will execute when token verification fail

func (*Middleware) Warnings

func (m *Middleware) Warnings() []string

Warnings show warnings if forwarded middleware settings is not safe.

Jump to

Keyboard shortcuts

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