diff --git a/test/e2e/v1/plugin/client.go b/test/e2e/v1/plugin/client.go index 476adb89..3499e882 100644 --- a/test/e2e/v1/plugin/client.go +++ b/test/e2e/v1/plugin/client.go @@ -3,6 +3,7 @@ package plugin import ( "crypto/tls" "fmt" + "net/http" "strconv" "github.com/onsi/ginkgo/v2" @@ -329,4 +330,76 @@ var _ = ginkgo.Describe("[Feature: Client-Plugins]", func() { ExpectResp([]byte("test")). Ensure() }) + + ginkgo.Describe("http2http", func() { + ginkgo.It("host header rewrite", func() { + serverConf := consts.DefaultServerConfig + + localPort := f.AllocPort() + remotePort := f.AllocPort() + clientConf := consts.DefaultClientConfig + fmt.Sprintf(` + [[proxies]] + name = "http2http" + type = "tcp" + remotePort = %d + [proxies.plugin] + type = "http2http" + localAddr = "127.0.0.1:%d" + hostHeaderRewrite = "rewrite.test.com" + `, remotePort, localPort) + + f.RunProcesses([]string{serverConf}, []string{clientConf}) + + localServer := httpserver.New( + httpserver.WithBindPort(localPort), + httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + _, _ = w.Write([]byte(req.Host)) + })), + ) + f.RunServer("", localServer) + + framework.NewRequestExpect(f). + Port(remotePort). + RequestModify(func(r *request.Request) { + r.HTTP().HTTPHost("example.com") + }). + ExpectResp([]byte("rewrite.test.com")). + Ensure() + }) + + ginkgo.It("set request header", func() { + serverConf := consts.DefaultServerConfig + + localPort := f.AllocPort() + remotePort := f.AllocPort() + clientConf := consts.DefaultClientConfig + fmt.Sprintf(` + [[proxies]] + name = "http2http" + type = "tcp" + remotePort = %d + [proxies.plugin] + type = "http2http" + localAddr = "127.0.0.1:%d" + requestHeaders.set.x-from-where = "frp" + `, remotePort, localPort) + + f.RunProcesses([]string{serverConf}, []string{clientConf}) + + localServer := httpserver.New( + httpserver.WithBindPort(localPort), + httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + _, _ = w.Write([]byte(req.Header.Get("x-from-where"))) + })), + ) + f.RunServer("", localServer) + + framework.NewRequestExpect(f). + Port(remotePort). + RequestModify(func(r *request.Request) { + r.HTTP().HTTPHost("example.com") + }). + ExpectResp([]byte("frp")). + Ensure() + }) + }) })