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

Function NewHTTPS2HTTPPlugin

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

Source from the content-addressed store, hash-verified

45}
46
47func NewHTTPS2HTTPPlugin(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 := &HTTPS2HTTPPlugin{
69 crtPath: crtPath,
70 keyPath: keyPath,
71 localAddr: localAddr,
72 hostHeaderRewrite: hostHeaderRewrite,
73 headers: headers,
74 l: listener,
75 }
76
77 rp := &httputil.ReverseProxy{
78 Director: func(req *http.Request) {
79 req.URL.Scheme = "http"
80 req.URL.Host = p.localAddr
81 if p.hostHeaderRewrite != "" {
82 req.Host = p.hostHeaderRewrite
83 }
84 for k, v := range p.headers {
85 req.Header.Set(k, v)
86 }
87 },
88 }
89
90 p.s = &http.Server{
91 Handler: rp,
92 }
93
94 var (
95 tlsConfig *tls.Config
96 err error
97 )
98 if crtPath != "" || keyPath != "" {
99 tlsConfig, err = p.genTLSConfig()
100 } else {
101 tlsConfig, err = transport.NewServerTLSConfig("", "", "")
102 tlsConfig.InsecureSkipVerify = true
103 }
104 if err != nil {

Callers

nothing calls this directly

Calls 3

genTLSConfigMethod · 0.95
NewProxyListenerFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected