diff --git a/configuration.go b/configuration.go index 9a7983de..250c4d78 100644 --- a/configuration.go +++ b/configuration.go @@ -397,6 +397,7 @@ func WithRemoteAddrPrivateSubnet(startIP, endIP string) Configurator { // WithSSLProxyHeader sets a SSLProxyHeaders key value pair. // Example: WithSSLProxyHeader("X-Forwarded-Proto", "https"). +// See `Context.IsSSL` for more. func WithSSLProxyHeader(headerKey, headerValue string) Configurator { return func(app *Application) { if app.config.SSLProxyHeaders == nil { @@ -1004,174 +1005,111 @@ type Configuration struct { var _ context.ConfigurationReadOnly = &Configuration{} // GetVHost returns the non-exported vhost config field. -// -// If original addr ended with :443 or :80, it will return the host without the port. -// If original addr was :https or :http, it will return localhost. -// If original addr was 0.0.0.0, it will return localhost. func (c Configuration) GetVHost() string { return c.vhost } -// GetLogLevel returns the `Configuration.LogLevel` field. -// The same (as `golog.LogLevel`) can be retrieved through `app.Logger().Level`. +// GetLogLevel returns the LogLevel field. func (c Configuration) GetLogLevel() string { return c.vhost } -// GetDisablePathCorrection returns the Configuration#DisablePathCorrection. -// DisablePathCorrection disables the correcting -// and redirecting or executing directly the handler of -// the requested path to the registered path -// for example, if /home/ path is requested but no handler for this Route found, -// then the Router checks if /home handler exists, if yes, -// (permanent)redirects the client to the correct path /home. +// GetDisablePathCorrection returns the DisablePathCorrection field. func (c Configuration) GetDisablePathCorrection() bool { return c.DisablePathCorrection } -// GetDisablePathCorrectionRedirection returns the Configuration.DisablePathCorrectionRedirection field. -// If DisablePathCorrectionRedirection set to true then it will fire the handler of the matching route without -// the last slash ("/") instead of send a redirection status. +// GetDisablePathCorrectionRedirection returns the DisablePathCorrectionRedirection field. func (c Configuration) GetDisablePathCorrectionRedirection() bool { return c.DisablePathCorrectionRedirection } -// GetEnablePathIntelligence returns the Configuration.EnablePathIntelligence field. +// GetEnablePathIntelligence returns the EnablePathIntelligence field. func (c Configuration) GetEnablePathIntelligence() bool { return c.EnablePathIntelligence } -// GetEnablePathEscape is the Configuration.EnablePathEscape, -// returns true when its escapes the path, the named parameters (if any). +// GetEnablePathEscape returns the EnablePathEscape field. func (c Configuration) GetEnablePathEscape() bool { return c.EnablePathEscape } -// GetForceLowercaseRouting returns the value of the Configuration.ForceLowercaseRouting setting. +// GetForceLowercaseRouting returns the ForceLowercaseRouting field. func (c Configuration) GetForceLowercaseRouting() bool { return c.ForceLowercaseRouting } -// GetFireMethodNotAllowed returns the Configuration.FireMethodNotAllowed. +// GetFireMethodNotAllowed returns the FireMethodNotAllowed field. func (c Configuration) GetFireMethodNotAllowed() bool { return c.FireMethodNotAllowed } -// GetEnableOptimizations returns whether -// the application has performance optimizations enabled. +// GetEnableOptimizations returns the EnableOptimizations. func (c Configuration) GetEnableOptimizations() bool { return c.EnableOptimizations } -// GetDisableBodyConsumptionOnUnmarshal returns the Configuration#GetDisableBodyConsumptionOnUnmarshal, -// manages the reading behavior of the context's body readers/binders. -// If returns true then the body consumption by the `context.UnmarshalBody/ReadJSON/ReadXML` -// is disabled. -// -// By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`, -// if this field set to true then a new buffer will be created to read from and the request body. -// The body will not be changed and existing data before the -// context.UnmarshalBody/ReadJSON/ReadXML will be not consumed. +// GetDisableBodyConsumptionOnUnmarshal returns the DisableBodyConsumptionOnUnmarshal field. func (c Configuration) GetDisableBodyConsumptionOnUnmarshal() bool { return c.DisableBodyConsumptionOnUnmarshal } -// GetFireEmptyFormError returns the Configuration.FireEmptyFormError value. -// If true then the `context.ReadBody/ReadForm` will return an `iris.ErrEmptyForm` -// on empty request form data. +// GetFireEmptyFormError returns the DisableBodyConsumptionOnUnmarshal field. func (c Configuration) GetFireEmptyFormError() bool { - return c.DisableBodyConsumptionOnUnmarshal + return c.FireEmptyFormError } -// GetDisableAutoFireStatusCode returns the Configuration.DisableAutoFireStatusCode. -// Returns true when the http error status code handler automatic execution turned off. +// GetDisableAutoFireStatusCode returns the DisableAutoFireStatusCode field. func (c Configuration) GetDisableAutoFireStatusCode() bool { return c.DisableAutoFireStatusCode } -// GetResetOnFireErrorCode returns the Configuration.ResetOnFireErrorCode. -// Returns true when the router should not respect the handler's error response and -// fire the registered error handler instead. -// -// See https://github.com/kataras/iris/issues/1531 +// GetResetOnFireErrorCode returns ResetOnFireErrorCode field. func (c Configuration) GetResetOnFireErrorCode() bool { return c.ResetOnFireErrorCode } -// GetTimeFormat returns the Configuration.TimeFormat, -// format for any kind of datetime parsing. +// GetTimeFormat returns the TimeFormat field. func (c Configuration) GetTimeFormat() string { return c.TimeFormat } -// GetCharset returns the Configuration.Charset, -// the character encoding for various rendering -// used for templates and the rest of the responses. +// GetCharset returns the Charset field. func (c Configuration) GetCharset() string { return c.Charset } -// GetPostMaxMemory returns the maximum configured post data size -// that a client can send to the server, this differs -// from the overral request body size which can be modified -// by the `context#SetMaxRequestBodySize` or `iris#LimitRequestBodySize`. -// -// Defaults to 32MB or 32 << 20 if you prefer. +// GetPostMaxMemory returns the PostMaxMemory field. func (c Configuration) GetPostMaxMemory() int64 { return c.PostMaxMemory } -// GetLocaleContextKey returns the configuration's LocaleContextKey value, -// used for i18n. +// GetLocaleContextKey returns the LocaleContextKey field. func (c Configuration) GetLocaleContextKey() string { return c.LocaleContextKey } -// GetLanguageContextKey returns the configuration's LanguageContextKey value, -// used for i18n. +// GetLanguageContextKey returns the LanguageContextKey field. func (c Configuration) GetLanguageContextKey() string { return c.LanguageContextKey } -// GetVersionContextKey returns the configuration's VersionContextKey value, -// used for API Versioning. +// GetVersionContextKey returns the VersionContextKey field. func (c Configuration) GetVersionContextKey() string { return c.VersionContextKey } -// GetViewLayoutContextKey returns the key of the context's user values' key -// which is being used to set the template -// layout from a middleware or the main handler. -// Overrides the parent's or the configuration's. +// GetViewLayoutContextKey returns the ViewLayoutContextKey field. func (c Configuration) GetViewLayoutContextKey() string { return c.ViewLayoutContextKey } -// GetViewDataContextKey returns the key of the context's user values' key -// which is being used to set the template -// binding data from a middleware or the main handler. +// GetViewDataContextKey returns the ViewDataContextKey field. func (c Configuration) GetViewDataContextKey() string { return c.ViewDataContextKey } -// GetRemoteAddrHeaders returns the allowed request headers names -// that can be valid to parse the client's IP based on. -// By-default no "X-" header is consired safe to be used for retrieving the -// client's IP address, because those headers can manually change by -// the client. But sometimes are useful e.g., when behind a proxy -// you want to enable the "X-Forwarded-For" or when cloudflare -// you want to enable the "CF-Connecting-IP", inneed you -// can allow the `ctx.RemoteAddr()` to use any header -// that the client may sent. -// -// Defaults to an empty map but an example usage is: -// RemoteAddrHeaders { -// "X-Real-Ip": true, -// "X-Forwarded-For": true, -// "CF-Connecting-IP": true, -// } -// -// Look `context.RemoteAddr()` for more. +// GetRemoteAddrHeaders returns the RemoteAddrHeaders field. func (c Configuration) GetRemoteAddrHeaders() map[string]bool { return c.RemoteAddrHeaders } @@ -1181,42 +1119,12 @@ func (c Configuration) GetSSLProxyHeaders() map[string]string { return c.SSLProxyHeaders } -// GetRemoteAddrPrivateSubnets returns the configuration's private sub-networks. -// They are used to be compared against -// IP Addresses fetched through `RemoteAddrHeaders` or `Request.RemoteAddr`. -// For details please navigate through: https://github.com/kataras/iris/issues/1453 -// Defaults to: -// { -// Start: net.ParseIP("10.0.0.0"), -// End: net.ParseIP("10.255.255.255"), -// }, -// { -// Start: net.ParseIP("100.64.0.0"), -// End: net.ParseIP("100.127.255.255"), -// }, -// { -// Start: net.ParseIP("172.16.0.0"), -// End: net.ParseIP("172.31.255.255"), -// }, -// { -// Start: net.ParseIP("192.0.0.0"), -// End: net.ParseIP("192.0.0.255"), -// }, -// { -// Start: net.ParseIP("192.168.0.0"), -// End: net.ParseIP("192.168.255.255"), -// }, -// { -// Start: net.ParseIP("198.18.0.0"), -// End: net.ParseIP("198.19.255.255"), -// } -// -// Look `context.RemoteAddr()` for more. +// GetRemoteAddrPrivateSubnets returns the RemoteAddrPrivateSubnets field. func (c Configuration) GetRemoteAddrPrivateSubnets() []netutil.IPRange { return c.RemoteAddrPrivateSubnets } -// GetOther returns the Configuration#Other map. +// GetOther returns the Other field. func (c Configuration) GetOther() map[string]interface{} { return c.Other } @@ -1342,6 +1250,15 @@ func WithConfiguration(c Configuration) Configurator { main.RemoteAddrPrivateSubnets = v } + if v := c.SSLProxyHeaders; len(v) > 0 { + if main.SSLProxyHeaders == nil { + main.SSLProxyHeaders = make(map[string]string, len(v)) + } + for key, value := range v { + main.SSLProxyHeaders[key] = value + } + } + if v := c.Other; len(v) > 0 { if main.Other == nil { main.Other = make(map[string]interface{}, len(v)) diff --git a/context/configuration.go b/context/configuration.go index c00f202f..b1824800 100644 --- a/context/configuration.go +++ b/context/configuration.go @@ -9,122 +9,58 @@ import "github.com/kataras/iris/v12/core/netutil" // safe or its useless to be called from a request handler. type ConfigurationReadOnly interface { // GetVHost returns the non-exported vhost config field. - // - // If original addr ended with :443 or :80, it will return the host without the port. - // If original addr was :https or :http, it will return localhost. - // If original addr was 0.0.0.0, it will return localhost. GetVHost() string - - // GetLogLevel returns the `Configuration.LogLevel` field. - // The same (as `golog.LogLevel`) can be retrieved through `app.Logger().Level`. + // GetLogLevel returns the LogLevel field. GetLogLevel() string - - // GetDisablePathCorrection returns the configuration.DisablePathCorrection, - // DisablePathCorrection corrects and redirects the requested path to the registered path - // for example, if /home/ path is requested but no handler for this Route found, - // then the Router checks if /home handler exists, if yes, - // (permant)redirects the client to the correct path /home. + // GetDisablePathCorrection returns the DisablePathCorrection field GetDisablePathCorrection() bool - // GetDisablePathCorrectionRedirection returns the Configuration.DisablePathCorrectionRedirection field. - // If DisablePathCorrectionRedirection set to true then it will handle paths as they are. - // it will fire the handler of the matching route without - // the last slash ("/") instead of send a redirection status. + // GetDisablePathCorrectionRedirection returns the DisablePathCorrectionRedirection field. GetDisablePathCorrectionRedirection() bool - // GetEnablePathIntelligence returns the Configuration.EnablePathIntelligence field. + // GetEnablePathIntelligence returns the EnablePathIntelligence field. GetEnablePathIntelligence() bool - // GetEnablePathEscape is the configuration.EnablePathEscape, - // returns true when its escapes the path, the named parameters (if any). + // GetEnablePathEscape returns the EnablePathEscape field. GetEnablePathEscape() bool - // GetForceLowercaseRouting returns the value of the `ForceLowercaseRouting` setting. + // GetForceLowercaseRouting returns the ForceLowercaseRouting field. GetForceLowercaseRouting() bool - // GetFireMethodNotAllowed returns the configuration.FireMethodNotAllowed. + // GetFireMethodNotAllowed returns the FireMethodNotAllowed field. GetFireMethodNotAllowed() bool - // GetDisableAutoFireStatusCode returns the configuration.DisableAutoFireStatusCode. - // Returns true when the http error status code handler automatic execution turned off. + // GetDisableAutoFireStatusCode returns the DisableAutoFireStatusCode field. GetDisableAutoFireStatusCode() bool - // ResetOnFireErrorCode if true then any previously response body or headers through - // response recorder or gzip writer will be ignored and the router - // will fire the registered (or default) HTTP error handler instead. - // See `core/router/handler#FireErrorCode` and `Context.EndRequest` for more details. - // - // Read more at: https://github.com/kataras/iris/issues/1531 - // - // Defaults to false. + // ResetOnFireErrorCode retruns the ResetOnFireErrorCode field. GetResetOnFireErrorCode() bool - // GetEnableOptimizations returns whether - // the application has performance optimizations enabled. + // GetEnableOptimizations returns the EnableOptimizations field. GetEnableOptimizations() bool - // GetDisableBodyConsumptionOnUnmarshal returns the configuration.GetDisableBodyConsumptionOnUnmarshal, - // manages the reading behavior of the context's body readers/binders. - // If returns true then the body consumption by the `context.UnmarshalBody/ReadJSON/ReadXML` - // is disabled. - // - // By-default io.ReadAll` is used to read the body from the `context.Request.Body which is an `io.ReadCloser`, - // if this field set to true then a new buffer will be created to read from and the request body. - // The body will not be changed and existing data before the - // context.UnmarshalBody/ReadJSON/ReadXML will be not consumed. + // GetDisableBodyConsumptionOnUnmarshal returns the DisableBodyConsumptionOnUnmarshal field. GetDisableBodyConsumptionOnUnmarshal() bool - // GetFireEmptyFormError returns the Configuration.FireEmptyFormError value. - // If true then the `context.ReadBody/ReadForm` will return an `iris.ErrEmptyForm` - // on empty request form data. + // GetFireEmptyFormError returns the FireEmptyFormError field. GetFireEmptyFormError() bool - // GetTimeFormat returns the configuration.TimeFormat, - // format for any kind of datetime parsing. + // GetTimeFormat returns the TimeFormat field. GetTimeFormat() string - - // GetCharset returns the configuration.Charset, - // the character encoding for various rendering - // used for templates and the rest of the responses. + // GetCharset returns the Charset field. GetCharset() string - - // GetPostMaxMemory returns the maximum configured post data size - // that a client can send to the server, this differs - // from the overral request body size which can be modified - // by the `context#SetMaxRequestBodySize` or `iris#LimitRequestBodySize`. - // - // Defaults to 32MB or 32 << 20 if you prefer. + // GetPostMaxMemory returns the PostMaxMemory field. GetPostMaxMemory() int64 - // GetTranslateLanguageContextKey returns the configuration's LocaleContextKey value, - // used for i18n. Defaults to "iris.locale". + // GetTranslateLanguageContextKey returns the LocaleContextKey field. GetLocaleContextKey() string - // GetLanguageContextKey returns the configuration's LanguageContextKey value, - // used for i18n. Defaults to "iris.locale.language". + // GetLanguageContextKey returns the LanguageContextKey field. GetLanguageContextKey() string - // GetVersionContextKey returns the configuration's VersionKey value, - // used for API Versioning. Defaults to "iris.api.version". + // GetVersionContextKey returns the VersionContextKey field. GetVersionContextKey() string - // GetViewLayoutContextKey returns the key of the context's user values' key - // which is being used to set the template - // layout from a middleware or the main handler. - // Overrides the parent's or the configuration's. + // GetViewLayoutContextKey returns the ViewLayoutContextKey field. GetViewLayoutContextKey() string - // GetViewDataContextKey returns the key of the context's user values' key - // which is being used to set the template - // binding data from a middleware or the main handler. + // GetViewDataContextKey returns the ViewDataContextKey field. GetViewDataContextKey() string - // GetRemoteAddrHeaders returns the allowed request headers names - // that can be valid to parse the client's IP based on. - // - // Defaults to: - // "X-Real-Ip": true, - // "X-Forwarded-For": true, - // "CF-Connecting-IP": false - // - // Look `context.RemoteAddr()` for more. + // GetRemoteAddrHeaders returns RemoteAddrHeaders field. GetRemoteAddrHeaders() map[string]bool - // GetRemoteAddrPrivateSubnets returns the configuration's private sub-networks. - // They are used to be compared against - // IP Addresses fetched through `RemoteAddrHeaders` or `Request.RemoteAddr`. - // For details please navigate through: https://github.com/kataras/iris/issues/1453 - // - // Look `context.RemoteAddr()` for more. + // GetRemoteAddrPrivateSubnets returns the RemoteAddrPrivateSubnets field. GetRemoteAddrPrivateSubnets() []netutil.IPRange // GetSSLProxyHeaders returns the SSLProxyHeaders field. GetSSLProxyHeaders() map[string]string - // GetOther returns the configuration.Other map. + + // GetOther returns the Other field. GetOther() map[string]interface{} }