1
0
Fork 0
mirror of https://github.com/Luzifer/preserve.git synced 2024-12-20 09:41:18 +00:00

Allow to override user-agent

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-06-14 03:04:28 +02:00
parent 7a61e1e970
commit e7cd25f4e3
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 11 additions and 1 deletions

View file

@ -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")
}

View file

@ -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"`
}{}