mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 07:35:07 +00:00
type http/tcpmux proxy support route_by_http_user, tcpmux support passthourgh mode (#2932)
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/pkg/rpc"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/utils"
|
||||
libdial "github.com/fatedier/golib/net/dial"
|
||||
)
|
||||
|
||||
@@ -20,10 +21,11 @@ type Request struct {
|
||||
protocol string
|
||||
|
||||
// for all protocol
|
||||
addr string
|
||||
port int
|
||||
body []byte
|
||||
timeout time.Duration
|
||||
addr string
|
||||
port int
|
||||
body []byte
|
||||
timeout time.Duration
|
||||
resolver *net.Resolver
|
||||
|
||||
// for http or https
|
||||
method string
|
||||
@@ -32,6 +34,8 @@ type Request struct {
|
||||
headers map[string]string
|
||||
tlsConfig *tls.Config
|
||||
|
||||
authValue string
|
||||
|
||||
proxyURL string
|
||||
}
|
||||
|
||||
@@ -40,8 +44,9 @@ func New() *Request {
|
||||
protocol: "tcp",
|
||||
addr: "127.0.0.1",
|
||||
|
||||
method: "GET",
|
||||
path: "/",
|
||||
method: "GET",
|
||||
path: "/",
|
||||
headers: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +113,11 @@ func (r *Request) HTTPHeaders(headers map[string]string) *Request {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Request) HTTPAuth(user, password string) *Request {
|
||||
r.authValue = utils.BasicAuth(user, password)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Request) TLSConfig(tlsConfig *tls.Config) *Request {
|
||||
r.tlsConfig = tlsConfig
|
||||
return r
|
||||
@@ -123,6 +133,11 @@ func (r *Request) Body(content []byte) *Request {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Request) Resolver(resolver *net.Resolver) *Request {
|
||||
r.resolver = resolver
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Request) Do() (*Response, error) {
|
||||
var (
|
||||
conn net.Conn
|
||||
@@ -150,11 +165,12 @@ func (r *Request) Do() (*Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
dialer := &net.Dialer{Resolver: r.resolver}
|
||||
switch r.protocol {
|
||||
case "tcp":
|
||||
conn, err = net.Dial("tcp", addr)
|
||||
conn, err = dialer.Dial("tcp", addr)
|
||||
case "udp":
|
||||
conn, err = net.Dial("udp", addr)
|
||||
conn, err = dialer.Dial("udp", addr)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid protocol")
|
||||
}
|
||||
@@ -198,11 +214,15 @@ func (r *Request) sendHTTPRequest(method, urlstr string, host string, headers ma
|
||||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
if r.authValue != "" {
|
||||
req.Header.Set("Authorization", r.authValue)
|
||||
}
|
||||
tr := &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
DualStack: true,
|
||||
Resolver: r.resolver,
|
||||
}).DialContext,
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
|
Reference in New Issue
Block a user