Skip to content

Commit

Permalink
Fix commit hash in User Agent can't be calculated when not present (#91)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CorentinB authored Jul 23, 2024
1 parent f5c4625 commit 1b95ca0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion internal/pkg/crawl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b95ca0

Please sign in to comment.