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:
parent
7a61e1e970
commit
e7cd25f4e3
2 changed files with 11 additions and 1 deletions
11
cache.go
11
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")
|
||||
}
|
||||
|
|
1
main.go
1
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"`
|
||||
}{}
|
||||
|
||||
|
|
Loading…
Reference in a new issue