diff --git a/cache.go b/cache.go index 5e0b3b9..363dfd5 100644 --- a/cache.go +++ b/cache.go @@ -13,7 +13,16 @@ import ( func renewCache(url string) (*meta, error) { var cachePath = urlToCachePath(url) - resp, err := http.Get(url) + req, err := http.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, errors.Wrap(err, "Unable to create request") + } + + if cfg.UserAgent != "" { + req.Header.Set("User-Agent", cfg.UserAgent) + } + + resp, err := http.DefaultClient.Do(req) if err != nil { return nil, errors.Wrap(err, "Unable to fetch source file") } diff --git a/main.go b/main.go index c2a3e7f..c5ebe5b 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ var ( Listen string `flag:"listen" default:":3000" description:"Port/IP to listen on"` LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"` StorageDir string `flag:"storage-dir" default:"./data/" description:"Where to store cached files"` + UserAgent string `flag:"user-agent" default:"" description:"Override user-agent"` VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` }{}