From 6dcc2fa7191bb09842f4b7e14fedf9c28ca93cfb Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 13 Apr 2021 14:08:15 -0500 Subject: [PATCH] flip signature, disabled by default --- README.md | 3 ++- app/main.go | 28 ++++++++++++++-------------- app/proxy/proxy.go | 38 +++++++++++++++++++------------------- app/proxy/proxy_test.go | 4 ++-- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a7b3089..7580a37 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ reproxy provides 2 endpoints for this purpose: -m, --max= max response size (default: 64000) [$MAX_SIZE] -g, --gzip enable gz compression [$GZIP] -x, --header= proxy headers [$HEADER] - --no-signature disable reproxy signature headers [$NO_SIGNATURE] + --signature enable reproxy signature headers [$SIGNATURE] --dbg debug mode [$DEBUG] ssl: @@ -132,6 +132,7 @@ assets: --assets.root= assets web root (default: /) [$ASSETS_ROOT] logger: + --logger.stdout enable stdout logging [$LOGGER_STDOUT] --logger.enabled enable access and error rotated logs [$LOGGER_ENABLED] --logger.file= location of access log (default: access.log) [$LOGGER_FILE] --logger.max-size= maximum size in megabytes before it gets rotated (default: 100) [$LOGGER_MAX_SIZE] diff --git a/app/main.go b/app/main.go index 2f6ed77..7532ed5 100644 --- a/app/main.go +++ b/app/main.go @@ -84,8 +84,8 @@ var opts struct { ExpectContinue time.Duration `long:"continue" env:"CONTINUE" default:"1s" description:"expect continue transport timeout"` } `group:"timeout" namespace:"timeout" env-namespace:"TIMEOUT"` - NoSignature bool `long:"no-signature" env:"NO_SIGNATURE" description:"disable reproxy signature headers"` - Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` + Signature bool `long:"signature" env:"SIGNATURE" description:"enable reproxy signature headers"` + Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` } var revision = "unknown" @@ -139,18 +139,18 @@ func main() { }() px := &proxy.Http{ - Version: revision, - Matcher: svc, - Address: opts.Listen, - MaxBodySize: opts.MaxSize, - AssetsLocation: opts.Assets.Location, - AssetsWebRoot: opts.Assets.WebRoot, - GzEnabled: opts.GzipEnabled, - SSLConfig: sslConfig, - ProxyHeaders: opts.ProxyHeaders, - AccessLog: accessLog, - StdOutEnabled: opts.Logger.StdOut, - DisableSignature: opts.NoSignature, + Version: revision, + Matcher: svc, + Address: opts.Listen, + MaxBodySize: opts.MaxSize, + AssetsLocation: opts.Assets.Location, + AssetsWebRoot: opts.Assets.WebRoot, + GzEnabled: opts.GzipEnabled, + SSLConfig: sslConfig, + ProxyHeaders: opts.ProxyHeaders, + AccessLog: accessLog, + StdOutEnabled: opts.Logger.StdOut, + Signature: opts.Signature, Timeouts: proxy.Timeouts{ ReadHeader: opts.Timeouts.ReadHeader, Write: opts.Timeouts.Write, diff --git a/app/proxy/proxy.go b/app/proxy/proxy.go index bed6e7e..1b92827 100644 --- a/app/proxy/proxy.go +++ b/app/proxy/proxy.go @@ -24,18 +24,18 @@ import ( // Http is a proxy server for both http and https type Http struct { // nolint golint Matcher - Address string - AssetsLocation string - AssetsWebRoot string - MaxBodySize int64 - GzEnabled bool - ProxyHeaders []string - SSLConfig SSLConfig - Version string - AccessLog io.Writer - StdOutEnabled bool - DisableSignature bool - Timeouts Timeouts + Address string + AssetsLocation string + AssetsWebRoot string + MaxBodySize int64 + GzEnabled bool + ProxyHeaders []string + SSLConfig SSLConfig + Version string + AccessLog io.Writer + StdOutEnabled bool + Signature bool + Timeouts Timeouts } // Matcher source info (server and route) to the destination url @@ -228,14 +228,14 @@ func (h *Http) gzipHandler() func(next http.Handler) http.Handler { } func (h *Http) signatureHandler() func(next http.Handler) http.Handler { - if h.DisableSignature { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - next.ServeHTTP(w, r) - }) - } + if h.Signature { + return R.AppInfo("reproxy", "umputun", h.Version) + } + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + }) } - return R.AppInfo("reproxy", "umputun", h.Version) } func (h *Http) accessLogHandler(wr io.Writer) func(next http.Handler) http.Handler { diff --git a/app/proxy/proxy_test.go b/app/proxy/proxy_test.go index 04224fa..84c860a 100644 --- a/app/proxy/proxy_test.go +++ b/app/proxy/proxy_test.go @@ -21,7 +21,7 @@ import ( func TestHttp_Do(t *testing.T) { port := rand.Intn(10000) + 40000 h := Http{Timeouts: Timeouts{ResponseHeader: 200 * time.Millisecond}, Address: fmt.Sprintf("127.0.0.1:%d", port), - AccessLog: io.Discard} + AccessLog: io.Discard, Signature: true} ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) defer cancel() @@ -94,7 +94,7 @@ func TestHttp_Do(t *testing.T) { func TestHttp_DoWithAssets(t *testing.T) { port := rand.Intn(10000) + 40000 h := Http{Timeouts: Timeouts{ResponseHeader: 200 * time.Millisecond}, Address: fmt.Sprintf("127.0.0.1:%d", port), - AccessLog: io.Discard, AssetsWebRoot: "/static", AssetsLocation: "testdata", DisableSignature: true} + AccessLog: io.Discard, AssetsWebRoot: "/static", AssetsLocation: "testdata"} ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) defer cancel()