mirror of
https://github.com/labstack/echo.git
synced 2025-07-13 01:30:31 +02:00
Proxy: Better errors + remote custom TLS (#1197)
Proxy will be more verbose on errors + possibility to configure custom transport (example: for custom TLS certificates)
This commit is contained in:
committed by
Vishal Rana
parent
fcdf096c2c
commit
bc37a3a792
52
middleware/proxy_1_11_test.go
Normal file
52
middleware/proxy_1_11_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
// +build go1.11
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProxy_1_11(t *testing.T) {
|
||||
// Setup
|
||||
url1, _ := url.Parse("http://127.0.0.1:27121")
|
||||
url2, _ := url.Parse("http://127.0.0.1:27122")
|
||||
|
||||
targets := []*ProxyTarget{
|
||||
{
|
||||
Name: "target 1",
|
||||
URL: url1,
|
||||
},
|
||||
{
|
||||
Name: "target 2",
|
||||
URL: url2,
|
||||
},
|
||||
}
|
||||
rb := NewRandomBalancer(nil)
|
||||
// must add targets:
|
||||
for _, target := range targets {
|
||||
assert.True(t, rb.AddTarget(target))
|
||||
}
|
||||
|
||||
// must ignore duplicates:
|
||||
for _, target := range targets {
|
||||
assert.False(t, rb.AddTarget(target))
|
||||
}
|
||||
|
||||
// Random
|
||||
e := echo.New()
|
||||
e.Use(Proxy(rb))
|
||||
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||
rec := newCloseNotifyRecorder()
|
||||
|
||||
// Remote unreachable
|
||||
rec = newCloseNotifyRecorder()
|
||||
req.URL.Path = "/api/users"
|
||||
e.ServeHTTP(rec, req)
|
||||
assert.Equal(t, "/api/users", req.URL.Path)
|
||||
assert.Equal(t, http.StatusServiceUnavailable, rec.Code)
|
||||
}
|
Reference in New Issue
Block a user