| 1 | // Copyright 2019 fatedier, fatedier@gmail.com |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //go:build !frps |
| 16 | |
| 17 | package client |
| 18 | |
| 19 | import ( |
| 20 | "crypto/tls" |
| 21 | "net/http" |
| 22 | "net/http/httputil" |
| 23 | |
| 24 | v1 "github.com/fatedier/frp/pkg/config/v1" |
| 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | Register(v1.PluginHTTP2HTTPS, NewHTTP2HTTPSPlugin) |
| 29 | } |
| 30 | |
| 31 | type HTTP2HTTPSPlugin struct { |
| 32 | opts *v1.HTTP2HTTPSPluginOptions |
| 33 | |
| 34 | *httpBridgePlugin |
| 35 | } |
| 36 | |
| 37 | func NewHTTP2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugin, error) { |
| 38 | opts := options.(*v1.HTTP2HTTPSPluginOptions) |
| 39 | |
| 40 | p := &HTTP2HTTPSPlugin{ |
| 41 | opts: opts, |
| 42 | } |
| 43 | |
| 44 | tr := &http.Transport{ |
| 45 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 46 | } |
| 47 | |
| 48 | rp := newHTTPBridgeReverseProxy( |
| 49 | func(r *httputil.ProxyRequest) { |
| 50 | r.Out.Header["X-Forwarded-For"] = r.In.Header["X-Forwarded-For"] |
| 51 | r.Out.Header["X-Forwarded-Host"] = r.In.Header["X-Forwarded-Host"] |
| 52 | r.Out.Header["X-Forwarded-Proto"] = r.In.Header["X-Forwarded-Proto"] |
| 53 | req := r.Out |
| 54 | rewriteHTTPPluginRequest(req, "https", p.opts.LocalAddr, p.opts.HostHeaderRewrite, p.opts.RequestHeaders) |
| 55 | }, |
| 56 | tr, |
| 57 | ) |
| 58 | p.httpBridgePlugin = newHTTPBridgePluginServer(rp, false) |
| 59 | |
| 60 | return p, nil |
| 61 | } |
| 62 | |
| 63 | func (p *HTTP2HTTPSPlugin) Name() string { |
| 64 | return v1.PluginHTTP2HTTPS |
| 65 | } |