flip signature, disabled by default

This commit is contained in:
Umputun 2021-04-13 14:08:15 -05:00
parent 510b29c3ec
commit 6dcc2fa719
4 changed files with 37 additions and 36 deletions

View File

@ -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]

View File

@ -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,

View File

@ -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 {

View File

@ -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()