MCPcopy Create free account
hub / github.com/M1r0ku/frp-Modify / NewHTTPS2HTTPSPlugin

Function NewHTTPS2HTTPSPlugin

frp-dev/pkg/plugin/client/https2https.go:47–118  ·  view source on GitHub ↗
(params map[string]string)

Source from the content-addressed store, hash-verified

45}
46
47func NewHTTPS2HTTPSPlugin(params map[string]string) (Plugin, error) {
48 crtPath := params["plugin_crt_path"]
49 keyPath := params["plugin_key_path"]
50 localAddr := params["plugin_local_addr"]
51 hostHeaderRewrite := params["plugin_host_header_rewrite"]
52 headers := make(map[string]string)
53 for k, v := range params {
54 if !strings.HasPrefix(k, "plugin_header_") {
55 continue
56 }
57 if k = strings.TrimPrefix(k, "plugin_header_"); k != "" {
58 headers[k] = v
59 }
60 }
61
62 if localAddr == "" {
63 return nil, fmt.Errorf("plugin_local_addr is required")
64 }
65
66 listener := NewProxyListener()
67
68 p := &HTTPS2HTTPSPlugin{
69 crtPath: crtPath,
70 keyPath: keyPath,
71 localAddr: localAddr,
72 hostHeaderRewrite: hostHeaderRewrite,
73 headers: headers,
74 l: listener,
75 }
76
77 tr := &http.Transport{
78 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
79 }
80
81 rp := &httputil.ReverseProxy{
82 Director: func(req *http.Request) {
83 req.URL.Scheme = "https"
84 req.URL.Host = p.localAddr
85 if p.hostHeaderRewrite != "" {
86 req.Host = p.hostHeaderRewrite
87 }
88 for k, v := range p.headers {
89 req.Header.Set(k, v)
90 }
91 },
92 Transport: tr,
93 }
94
95 p.s = &http.Server{
96 Handler: rp,
97 }
98
99 var (
100 tlsConfig *tls.Config
101 err error
102 )
103 if crtPath != "" || keyPath != "" {
104 tlsConfig, err = p.genTLSConfig()

Callers

nothing calls this directly

Calls 3

genTLSConfigMethod · 0.95
NewProxyListenerFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected