mirror of https://github.com/gofiber/fiber.git
🐛 bug: fix proxy overwrote the wrong scheme (#2004)
* 🐛 bug: fix proxy overwrote the wrong scheme * ✅ fix: fix io not exist in go1.14pull/2013/head
parent
e5eb8d3c98
commit
e8a2ba363c
|
@ -123,11 +123,13 @@ func Do(c *fiber.Ctx, addr string) error {
|
|||
res := c.Response()
|
||||
originalURL := utils.CopyString(c.OriginalURL())
|
||||
defer req.SetRequestURI(originalURL)
|
||||
req.SetRequestURI(addr)
|
||||
|
||||
copiedURL := utils.CopyString(addr)
|
||||
req.SetRequestURI(copiedURL)
|
||||
// NOTE: if req.isTLS is true, SetRequestURI keeps the scheme as https.
|
||||
// issue reference:
|
||||
// https://github.com/gofiber/fiber/issues/1762
|
||||
if scheme := getScheme(utils.UnsafeBytes(addr)); len(scheme) > 0 {
|
||||
if scheme := getScheme(utils.UnsafeBytes(copiedURL)); len(scheme) > 0 {
|
||||
req.URI().SetSchemeBytes(scheme)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -362,3 +363,30 @@ func Test_Proxy_Do_RestoreOriginalURL(t *testing.T) {
|
|||
utils.AssertEqual(t, nil, err1)
|
||||
utils.AssertEqual(t, nil, err2)
|
||||
}
|
||||
|
||||
func Test_Proxy_Do_HTTP_Prefix_URL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, addr := createProxyTestServer(func(c *fiber.Ctx) error {
|
||||
return c.SendString("hello world")
|
||||
}, t)
|
||||
|
||||
app := fiber.New(fiber.Config{DisableStartupMessage: true})
|
||||
app.Get("/*", func(c *fiber.Ctx) error {
|
||||
path := c.OriginalURL()
|
||||
url := strings.TrimPrefix(path, "/")
|
||||
|
||||
utils.AssertEqual(t, "http://"+addr, url)
|
||||
if err := Do(c, url); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Response().Header.Del(fiber.HeaderServer)
|
||||
return nil
|
||||
})
|
||||
|
||||
resp, err := app.Test(httptest.NewRequest(http.MethodGet, "/http://"+addr, nil))
|
||||
utils.AssertEqual(t, nil, err)
|
||||
s, err := ioutil.ReadAll(resp.Body)
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "hello world", string(s))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue