small update on reverse proxy and xforwarded middlewares

This commit is contained in:
yusing
2024-12-01 05:04:57 +08:00
parent a4f44348ef
commit 863bb3f474
7 changed files with 76 additions and 67 deletions

View File

@@ -6,13 +6,14 @@ import (
"strings"
"testing"
gphttp "github.com/yusing/go-proxy/internal/net/http"
"github.com/yusing/go-proxy/internal/net/types"
. "github.com/yusing/go-proxy/internal/utils/testing"
)
func TestSetRealIPOpts(t *testing.T) {
opts := OptionsRaw{
"header": "X-Real-IP",
"header": gphttp.HeaderXRealIP,
"from": []string{
"127.0.0.0/8",
"192.168.0.0/16",
@@ -21,7 +22,7 @@ func TestSetRealIPOpts(t *testing.T) {
"recursive": true,
}
optExpected := &realIPOpts{
Header: "X-Real-IP",
Header: gphttp.HeaderXRealIP,
From: []*types.CIDR{
{
IP: net.ParseIP("127.0.0.0"),
@@ -50,7 +51,7 @@ func TestSetRealIPOpts(t *testing.T) {
func TestSetRealIP(t *testing.T) {
const (
testHeader = "X-Real-IP"
testHeader = gphttp.HeaderXRealIP
testRealIP = "192.168.1.1"
)
opts := OptionsRaw{
@@ -73,5 +74,5 @@ func TestSetRealIP(t *testing.T) {
t.Log(traces)
ExpectEqual(t, result.ResponseStatus, http.StatusOK)
ExpectEqual(t, strings.Split(result.RemoteAddr, ":")[0], testRealIP)
ExpectEqual(t, result.RequestHeaders.Get(xForwardedFor), testRealIP)
ExpectEqual(t, result.RequestHeaders.Get(gphttp.HeaderXForwardedFor), testRealIP)
}