Skip to content

Commit

Permalink
archiver: allow to override the archive type via query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Jul 27, 2023
1 parent ba69a5d commit 198d4fa
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions internal/http/services/archiver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,21 @@ func (s *svc) Handler() http.Handler {
return
}

userAgent := ua.Parse(r.Header.Get("User-Agent"))

archName := s.config.Name
if userAgent.OS == ua.Windows {
archName += ".zip"
} else {
archName += ".tar"
archTypeParam, ok := v["arch_type"] // optional, either "tar" or "zip"
var archType string
if ok {
archType = archTypeParam[0]
}
if !ok || archTypeParam[0] != "tar" && archTypeParam[0] != "zip" {
// in case of missing or bogus arch_type, detect it via user-agent
userAgent := ua.Parse(r.Header.Get("User-Agent"))
if userAgent.OS == ua.Windows {
archType = "zip"
} else {
archType = "tar"
}
archName += "." + archType
}

log.Debug().Msg("Requested the following files/folders to archive: " + render.Render(files))
Expand All @@ -244,7 +252,7 @@ func (s *svc) Handler() http.Handler {
rw.Header().Set("Content-Transfer-Encoding", "binary")

// create the archive
if userAgent.OS == ua.Windows {
if archType == "zip" {
err = arch.CreateZip(ctx, rw)
} else {
err = arch.CreateTar(ctx, rw)
Expand Down

0 comments on commit 198d4fa

Please sign in to comment.