server/proxy: simplify the code (#3488)

This commit is contained in:
fatedier
2023-06-16 00:14:19 +08:00
committed by GitHub
parent 9ba6a06470
commit e1cef053be
10 changed files with 235 additions and 173 deletions

View File

@ -17,10 +17,10 @@ package proxy
import (
"io"
"net"
"reflect"
"strings"
libio "github.com/fatedier/golib/io"
"golang.org/x/time/rate"
"github.com/fatedier/frp/pkg/config"
"github.com/fatedier/frp/pkg/util/limit"
@ -30,6 +30,10 @@ import (
"github.com/fatedier/frp/server/metrics"
)
func init() {
RegisterProxyFactory(reflect.TypeOf(&config.HTTPProxyConf{}), NewHTTPProxy)
}
type HTTPProxy struct {
*BaseProxy
cfg *config.HTTPProxyConf
@ -37,6 +41,17 @@ type HTTPProxy struct {
closeFuncs []func()
}
func NewHTTPProxy(baseProxy *BaseProxy, cfg config.ProxyConf) Proxy {
unwrapped, ok := cfg.(*config.HTTPProxyConf)
if !ok {
return nil
}
return &HTTPProxy{
BaseProxy: baseProxy,
cfg: unwrapped,
}
}
func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
xl := pxy.xl
routeConfig := vhost.RouteConfig{
@ -137,10 +152,6 @@ func (pxy *HTTPProxy) GetConf() config.ProxyConf {
return pxy.cfg
}
func (pxy *HTTPProxy) GetLimiter() *rate.Limiter {
return pxy.limiter
}
func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err error) {
xl := pxy.xl
rAddr, errRet := net.ResolveTCPAddr("tcp", remoteAddr)