sequence

This paper mainly studies the hostFilter of Dubo-Go-proxy

hostFilter

dubbo-go-proxy/pkg/filter/host/host.go

// hostFilter is a filter for host.
type hostFilter struct {
	host string
}

// New create host filter.
func New(host string) filter.Filter {
	return &hostFilter{host: host}
}
Copy the code

HostFilter New creates hostFilter based on host

Do

dubbo-go-proxy/pkg/filter/host/host.go

func (f hostFilter) Do() fc.FilterFunc {
	return func(c fc.Context) {
		f.doHostFilter(c.(*contexthttp.HttpContext))
	}
}

func (f hostFilter) doHostFilter(c *contexthttp.HttpContext) {
	c.Request.Host = f.host
	c.Next()
}
Copy the code

The Do method executes the doHostFilter method, which sets f.host to c.equest.host and then executes c.next ()

httpFilter

dubbo-go-proxy/pkg/proxy/listener.go

func httpFilter(ctx *h.HttpContext, request fc.IntegrationRequest) { if len(request.Host) ! = 0 { ctx.AppendFilterFunc(host.New(request.Host).Do()) } if len(request.Path) ! = 0 { ctx.AppendFilterFunc(replacepath.New(request.Path).Do()) } }Copy the code

The httpFilter method appends host.New(request.host) to the Filters through AppendFilterFunc

summary

The hostFilter for dubo-Go-proxy sets f.host to c.equest.Host and then executes c.next ().

doc

  • dubbo-go-proxy