From 1b95ca02f18c8bf9e08b516292728cfa9833634f Mon Sep 17 00:00:00 2001 From: Corentin Barreau Date: Tue, 23 Jul 2024 17:33:59 +0200 Subject: [PATCH] Fix commit hash in User Agent can't be calculated when not present (#91) * Fix: commit hash in User Agent can't be calculated when not present * Fix #89: default to "unknown" * Fix #89: default to "unknown_version" & truncate hash only if it's a hash * Fix #89: update comment in GetVersion --- internal/pkg/crawl/config.go | 8 +++++++- internal/pkg/utils/version.go | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/pkg/crawl/config.go b/internal/pkg/crawl/config.go index 0fbbd687..be007992 100644 --- a/internal/pkg/crawl/config.go +++ b/internal/pkg/crawl/config.go @@ -245,7 +245,13 @@ func GenerateCrawlConfig(config *config.Config) (*Crawl, error) { c.UserAgent = config.UserAgent } else { version := utils.GetVersion() - c.UserAgent = "Mozilla/5.0 (compatible; archive.org_bot +http://archive.org/details/archive.org_bot) Zeno/" + version.Version[:7] + " warc/" + version.WarcVersion + + // If Version is a commit hash, we only take the first 7 characters + if len(version.Version) == 40 { + version.Version = version.Version[:7] + } + + c.UserAgent = "Mozilla/5.0 (compatible; archive.org_bot +http://archive.org/details/archive.org_bot) Zeno/" + version.Version + " warc/" + version.WarcVersion } c.Headless = config.Headless diff --git a/internal/pkg/utils/version.go b/internal/pkg/utils/version.go index 7e9fe5e9..89ba3a84 100644 --- a/internal/pkg/utils/version.go +++ b/internal/pkg/utils/version.go @@ -12,8 +12,8 @@ type Version struct { } func GetVersion() (version Version) { - // Defaults to master - version.Version = "master" + // Defaults to "unknown_version" + version.Version = "unknown_version" if info, ok := debug.ReadBuildInfo(); ok { // Determine Zeno's version based on Git data