| 1 | // Copyright 2024 The frp Authors |
| 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 | "net/http/httputil" |
| 21 | |
| 22 | v1 "github.com/fatedier/frp/pkg/config/v1" |
| 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | Register(v1.PluginHTTP2HTTP, NewHTTP2HTTPPlugin) |
| 27 | } |
| 28 | |
| 29 | type HTTP2HTTPPlugin struct { |
| 30 | opts *v1.HTTP2HTTPPluginOptions |
| 31 | |
| 32 | *httpBridgePlugin |
| 33 | } |
| 34 | |
| 35 | func NewHTTP2HTTPPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugin, error) { |
| 36 | opts := options.(*v1.HTTP2HTTPPluginOptions) |
| 37 | |
| 38 | p := &HTTP2HTTPPlugin{ |
| 39 | opts: opts, |
| 40 | } |
| 41 | |
| 42 | rp := newHTTPBridgeReverseProxy( |
| 43 | func(r *httputil.ProxyRequest) { |
| 44 | req := r.Out |
| 45 | rewriteHTTPPluginRequest(req, "http", p.opts.LocalAddr, p.opts.HostHeaderRewrite, p.opts.RequestHeaders) |
| 46 | }, |
| 47 | nil, |
| 48 | ) |
| 49 | p.httpBridgePlugin = newHTTPBridgePluginServer(rp, false) |
| 50 | |
| 51 | return p, nil |
| 52 | } |
| 53 | |
| 54 | func (p *HTTP2HTTPPlugin) Name() string { |
| 55 | return v1.PluginHTTP2HTTP |
| 56 | } |