From 5f06821dc00fc238d2d1ea21a8d38d175a7d2642 Mon Sep 17 00:00:00 2001 From: Martin Chodur Date: Wed, 1 Jul 2020 22:59:51 +0200 Subject: [PATCH] fix swift: fixed missing Content-Type headers issue (#2665) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix swift: fixed missing Content-Type headers issue Signed-off-by: Martin Chodur * chore CHANGELOG: add PR id Signed-off-by: Martin Chodur * fix swift: fixed invalid lower range boundary Signed-off-by: Martin Chodur * fix swift: fixed typo in ENV variable for testing bucket Signed-off-by: Martin Chodur Co-authored-by: Giedrius Statkevičius --- CHANGELOG.md | 6 ++++++ pkg/objstore/swift/swift.go | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b5d31172e..95ff63fda9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ We use *breaking* word for marking changes that are not backward compatible (rel ## Unreleased +### Fixed + +* [#2665](https://github.com/thanos-io/thanos/pull/2665) Swift: fix issue with missing Content-Type HTTP headers. + +### Changed + ## [v0.14.0](https://github.com/thanos-io/thanos/releases) - IN PROGRESS ### Fixed diff --git a/pkg/objstore/swift/swift.go b/pkg/objstore/swift/swift.go index c11715ce4f..d15a455cd5 100644 --- a/pkg/objstore/swift/swift.go +++ b/pkg/objstore/swift/swift.go @@ -93,7 +93,7 @@ func (c *Container) Iter(ctx context.Context, dir string, f func(string) error) dir = strings.TrimSuffix(dir, DirDelim) + DirDelim } - options := &objects.ListOpts{Full: false, Prefix: dir, Delimiter: DirDelim} + options := &objects.ListOpts{Full: true, Prefix: dir, Delimiter: DirDelim} return objects.List(c.client, c.name, options).EachPage(func(page pagination.Page) (bool, error) { objectNames, err := objects.ExtractNames(page) if err != nil { @@ -120,9 +120,17 @@ func (c *Container) Get(ctx context.Context, name string) (io.ReadCloser, error) // GetRange returns a new range reader for the given object name and range. func (c *Container) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error) { + lowerLimit := "" + upperLimit := "" + if off >= 0 { + lowerLimit = fmt.Sprintf("%d", off) + } + if length > 0 { + upperLimit = fmt.Sprintf("%d", off+length-1) + } options := objects.DownloadOpts{ Newest: true, - Range: fmt.Sprintf("bytes=%d-%d", off, off+length-1), + Range: fmt.Sprintf("bytes=%s-%s", lowerLimit, upperLimit), } response := objects.Download(c.client, c.name, name, options) return response.Body, response.Err @@ -251,7 +259,7 @@ func configFromEnv() SwiftConfig { ProjectName: os.Getenv("OS_PROJECT_NAME"), UserDomainID: os.Getenv("OS_USER_DOMAIN_ID"), UserDomainName: os.Getenv("OS_USER_DOMAIN_NAME"), - ProjectDomainID: os.Getenv("OS_PROJET_DOMAIN_ID"), + ProjectDomainID: os.Getenv("OS_PROJECT_DOMAIN_ID"), ProjectDomainName: os.Getenv("OS_PROJECT_DOMAIN_NAME"), }