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

Function NewHTTP2HTTPSPlugin

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

Source from the content-addressed store, hash-verified

42}
43
44func NewHTTP2HTTPSPlugin(params map[string]string) (Plugin, error) {
45 localAddr := params["plugin_local_addr"]
46 hostHeaderRewrite := params["plugin_host_header_rewrite"]
47 headers := make(map[string]string)
48 for k, v := range params {
49 if !strings.HasPrefix(k, "plugin_header_") {
50 continue
51 }
52 if k = strings.TrimPrefix(k, "plugin_header_"); k != "" {
53 headers[k] = v
54 }
55 }
56
57 if localAddr == "" {
58 return nil, fmt.Errorf("plugin_local_addr is required")
59 }
60
61 listener := NewProxyListener()
62
63 p := &HTTP2HTTPSPlugin{
64 localAddr: localAddr,
65 hostHeaderRewrite: hostHeaderRewrite,
66 headers: headers,
67 l: listener,
68 }
69
70 tr := &http.Transport{
71 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
72 }
73
74 rp := &httputil.ReverseProxy{
75 Director: func(req *http.Request) {
76 req.URL.Scheme = "https"
77 req.URL.Host = p.localAddr
78 if p.hostHeaderRewrite != "" {
79 req.Host = p.hostHeaderRewrite
80 }
81 for k, v := range p.headers {
82 req.Header.Set(k, v)
83 }
84 },
85 Transport: tr,
86 }
87
88 p.s = &http.Server{
89 Handler: rp,
90 ReadHeaderTimeout: 0,
91 }
92
93 go func() {
94 _ = p.s.Serve(listener)
95 }()
96
97 return p, nil
98}
99
100func (p *HTTP2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) {
101 wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn)

Callers

nothing calls this directly

Calls 2

NewProxyListenerFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected