New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide extract_headers_path
, extract_headers_ttl
#699
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual trick to do this plays only in the toJSON and fromJSON sides.
From JSON does a Default()
first so Config
will have the values correctly set. If the values in JSON for these fields are the type-default ("" or 0), then the Config should not be overwritten (SetIfNotDefault
takes care of this).
In order to hide these values when they are the default, ToJSON sets ""
when the value of Config
is the default.
Note that, with this change, Config.ExtractHeadersPath
will be unset and this will break. We expect Config
to always have a valid value for those fields. We just want to hide the fields in the json by omitting them when they are the default.
api/ipfsproxy/config.go
Outdated
@@ -116,8 +114,6 @@ func (cfg *Config) Default() error { | |||
cfg.WriteTimeout = DefaultWriteTimeout | |||
cfg.IdleTimeout = DefaultIdleTimeout | |||
cfg.ExtractHeadersExtra = nil | |||
cfg.ExtractHeadersPath = DefaultExtractHeadersPath | |||
cfg.ExtractHeadersTTL = DefaultExtractHeadersTTL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this
api/ipfsproxy/config.go
Outdated
@@ -259,6 +251,9 @@ func (cfg *Config) toJSONConfig() (jcfg *jsonConfig, err error) { | |||
|
|||
jcfg.ExtractHeadersExtra = cfg.ExtractHeadersExtra | |||
jcfg.ExtractHeadersPath = cfg.ExtractHeadersPath | |||
if !(cfg.ExtractHeadersTTL > 0) { | |||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning here breaks the flow of the function. If we were to add things at the end of this function we would need to remember that the function may have been aborted before.
api/ipfsproxy/config.go
Outdated
@@ -250,8 +258,14 @@ func (cfg *Config) toJSONConfig() (jcfg *jsonConfig, err error) { | |||
jcfg.NodeHTTPS = cfg.NodeHTTPS | |||
|
|||
jcfg.ExtractHeadersExtra = cfg.ExtractHeadersExtra | |||
jcfg.ExtractHeadersPath = cfg.ExtractHeadersPath | |||
if !(cfg.ExtractHeadersTTL > 0) { | |||
if cfg.ExtractHeadersPath == DefaultExtractHeadersPath { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first case is not necessary because the json object is empty. So the if
should only have the second case.
api/ipfsproxy/config.go
Outdated
} | ||
|
||
if cfg.ExtractHeadersTTL == DefaultExtractHeadersTTL { | ||
jcfg.ExtractHeadersTTL = "" | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before. Keep consistency.
if ttl := cfg.ExtractHeadersTTL; ttl != DefaultExtractHeadersTTL { jcfg.ExtractHeadersTTL = ttl.String() }
do not return
proxy: "extract_headers_path" and "extract_headers_ttl" should be hidden options in the config
7a5b88e
to
27a5999
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
proxy: "extract_headers_path" and "extract_headers_ttl" should be
hidden options in the config
Fixes #698