1
0
mirror of https://github.com/umputun/reproxy.git synced 2025-09-16 08:46:17 +02:00

add-nosignature mode, rename leftovers from dpx

This commit is contained in:
Umputun
2021-04-06 23:17:50 -05:00
parent a27b718d59
commit cfb8d8df14
4 changed files with 33 additions and 20 deletions

View File

@@ -19,8 +19,8 @@ import (
// Docker provide watch compatible changes from containers
// and maps by default from ^/api/%s/(.*) to http://%s:%d/$1, i.e. http://example.com/api/my_container/something
// will be mapped to http://172.17.42.1:8080/something. Ip will be the internal ip of the container and port - exposed the one
// Alternatively labels can alter this. dpx.route sets source route, and dpx.dest sets the destination. Optional dpx.server enforces
// match by server name (hostname).
// Alternatively labels can alter this. reproxy.route sets source route, and reproxy.dest sets the destination.
// Optional reproxy.server enforces match by server name (hostname).
type Docker struct {
DockerClient DockerClient
Excludes []string

View File

@@ -15,7 +15,7 @@ func TestFile_Events(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
tmp, err := ioutil.TempFile(os.TempDir(), "dpx-events")
tmp, err := ioutil.TempFile(os.TempDir(), "reproxy-events")
require.NoError(t, err)
tmp.Close()
defer os.Remove(tmp.Name())

View File

@@ -16,7 +16,6 @@ import (
log "github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
R "github.com/go-pkgz/rest"
"github.com/go-pkgz/rest/logger"
"github.com/gorilla/handlers"
"github.com/pkg/errors"
@@ -26,16 +25,17 @@ import (
// Http is a proxy server for both http and https
type Http struct {
Matcher
Address string
TimeOut time.Duration
AssetsLocation string
AssetsWebRoot string
MaxBodySize int64
GzEnabled bool
ProxyHeaders []string
SSLConfig SSLConfig
Version string
AccessLog io.Writer
Address string
TimeOut time.Duration
AssetsLocation string
AssetsWebRoot string
MaxBodySize int64
GzEnabled bool
ProxyHeaders []string
SSLConfig SSLConfig
Version string
AccessLog io.Writer
DisableSignature bool
}
// Matcher source info (server and route) to the destination url
@@ -71,10 +71,9 @@ func (h *Http) Run(ctx context.Context) error {
handler := R.Wrap(h.proxyHandler(),
R.Recoverer(lgr.Default()),
R.AppInfo("reproxy", "umputun", h.Version),
h.signatureHandler,
R.Ping,
h.healthMiddleware,
logger.New(logger.Prefix("[DEBUG] PROXY")).Handler,
h.accessLogHandler(h.AccessLog),
R.SizeLimit(h.MaxBodySize),
R.Headers(h.ProxyHeaders...),
@@ -199,6 +198,15 @@ func (h *Http) gzipHandler() func(next http.Handler) http.Handler {
}
}
func (h *Http) signatureHandler(next http.Handler) http.Handler {
if h.DisableSignature {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
})
}
return R.AppInfo("reproxy", "umputun", h.Version)(next)
}
func (h *Http) accessLogHandler(wr io.Writer) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return handlers.CombinedLoggingHandler(wr, next)
@@ -217,7 +225,12 @@ func (h *Http) makeHTTPServer(addr string, router http.Handler) *http.Server {
func (h *Http) setXRealIP(r *http.Request) {
ip, _, err := net.SplitHostPort(r.RemoteAddr)
remoteIP := r.Header.Get("X-Forwarded-For")
if remoteIP == "" {
remoteIP = r.RemoteAddr
}
ip, _, err := net.SplitHostPort(remoteIP)
if err != nil {
return
}

View File

@@ -21,7 +21,7 @@ import (
func TestHttp_Do(t *testing.T) {
port := rand.Intn(10000) + 40000
h := Http{TimeOut: 200 * time.Millisecond, Address: fmt.Sprintf("127.0.0.1:%d", port)}
h := Http{TimeOut: 200 * time.Millisecond, Address: fmt.Sprintf("127.0.0.1:%d", port), AccessLog: io.Discard}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
@@ -63,7 +63,7 @@ func TestHttp_Do(t *testing.T) {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "response /567/something", string(body))
assert.Equal(t, "dpx", resp.Header.Get("App-Name"))
assert.Equal(t, "reproxy", resp.Header.Get("App-Name"))
assert.Equal(t, "v1", resp.Header.Get("h1"))
}
@@ -77,7 +77,7 @@ func TestHttp_Do(t *testing.T) {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "response /123/something", string(body))
assert.Equal(t, "dpx", resp.Header.Get("App-Name"))
assert.Equal(t, "reproxy", resp.Header.Get("App-Name"))
assert.Equal(t, "v1", resp.Header.Get("h1"))
}