aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-02-19 14:40:33 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-02-19 14:40:33 +0100
commit1a84987c7e28094f4e65bfb0fa03fdf5059ef6cc (patch)
tree26e8afc474d838259a75cbb7c62bd942bc7e8d37
parentbe80f087d7857d7ca1418aa797eadde39806cbf8 (diff)
downloadgo-schwift-1a84987c7e28094f4e65bfb0fa03fdf5059ef6cc.tar.gz
initialize .Headers on accounts/containers during GET requests
-rw-r--r--container_iterator_test.go10
-rw-r--r--iterator.go27
-rw-r--r--object.go2
-rw-r--r--object_iterator_test.go10
4 files changed, 47 insertions, 2 deletions
diff --git a/container_iterator_test.go b/container_iterator_test.go
index df4ab80..70620ad 100644
--- a/container_iterator_test.go
+++ b/container_iterator_test.go
@@ -81,6 +81,7 @@ func TestContainerIterator(t *testing.T) {
expectContainerInfos(t, cis)
//test Foreach
+ a.Invalidate()
iter = a.Containers()
iter.Prefix = "schwift-test-listing"
idx := 0
@@ -91,7 +92,12 @@ func TestContainerIterator(t *testing.T) {
}))
expectInt(t, idx, 4)
+ if a.headers == nil {
+ t.Error("ContainerIterator.Foreach did not initialize Account.Headers")
+ }
+
//test ForeachDetailed
+ a.Invalidate()
iter = a.Containers()
iter.Prefix = "schwift-test-listing"
idx = 0
@@ -102,6 +108,10 @@ func TestContainerIterator(t *testing.T) {
}))
expectInt(t, idx, 4)
+ if a.headers == nil {
+ t.Error("ContainerIterator.ForeachDetailed did not initialize Account.Headers")
+ }
+
//test Collect
iter = a.Containers()
iter.Prefix = "schwift-test-listing"
diff --git a/iterator.go b/iterator.go
index aebeb91..acbc449 100644
--- a/iterator.go
+++ b/iterator.go
@@ -20,6 +20,7 @@ package schwift
import (
"encoding/json"
+ "net/http"
"strconv"
"strings"
)
@@ -32,6 +33,9 @@ type iteratorInterface interface {
getPrefix() string
getHeaders() map[string]string
getOptions() *RequestOptions
+ //putHeader initializes the AccountHeaders/ContainerHeaders field of the
+ //Account/Container using the response headers from the GET request.
+ putHeader(http.Header) error
}
func (i ContainerIterator) getAccount() *Account { return i.Account }
@@ -40,12 +44,30 @@ func (i ContainerIterator) getPrefix() string { return i.Prefix }
func (i ContainerIterator) getHeaders() map[string]string { return i.Headers }
func (i ContainerIterator) getOptions() *RequestOptions { return i.Options }
+func (i ContainerIterator) putHeader(hdr http.Header) error {
+ headers := AccountHeaders(headersFromHTTP(hdr))
+ if err := headers.Validate(); err != nil {
+ return err
+ }
+ i.Account.headers = &headers
+ return nil
+}
+
func (i ObjectIterator) getAccount() *Account { return i.Container.Account() }
func (i ObjectIterator) getContainerName() string { return i.Container.Name() }
func (i ObjectIterator) getPrefix() string { return i.Prefix }
func (i ObjectIterator) getHeaders() map[string]string { return i.Headers }
func (i ObjectIterator) getOptions() *RequestOptions { return i.Options }
+func (i ObjectIterator) putHeader(hdr http.Header) error {
+ headers := ContainerHeaders(headersFromHTTP(hdr))
+ if err := headers.Validate(); err != nil {
+ return err
+ }
+ i.Container.headers = &headers
+ return nil
+}
+
//iteratorBase provides shared behavior for ContainerIterator and ObjectIterator.
type iteratorBase struct {
i iteratorInterface
@@ -116,7 +138,7 @@ func (b *iteratorBase) nextPage(limit int) ([]string, error) {
b.eof = false
b.marker = result[len(result)-1]
}
- return result, nil
+ return result, b.i.putHeader(resp.Header)
}
func (b *iteratorBase) nextPageDetailed(limit int, data interface{}) error {
@@ -133,6 +155,9 @@ func (b *iteratorBase) nextPageDetailed(limit int, data interface{}) error {
if err == nil {
err = closeErr
}
+ if err == nil {
+ err = b.i.putHeader(resp.Header)
+ }
return err
}
diff --git a/object.go b/object.go
index 3812f67..a2a68e1 100644
--- a/object.go
+++ b/object.go
@@ -263,4 +263,4 @@ func (o *Object) Invalidate() {
}
//TODO Object.Copy(), Object.Move(), Object.Download()
-//TODO does Object.Upload() have the right API?
+//TODO provide a companion to Object.Upload() to connect it with content-generating functions where an io.Writer needs to be given
diff --git a/object_iterator_test.go b/object_iterator_test.go
index 86a96e9..64cb6a2 100644
--- a/object_iterator_test.go
+++ b/object_iterator_test.go
@@ -94,6 +94,7 @@ func TestObjectIterator(t *testing.T) {
expectObjectInfos(t, ois)
//test Foreach
+ c.Invalidate()
iter = c.Objects()
iter.Prefix = "schwift-test-listing"
idx := 0
@@ -104,7 +105,12 @@ func TestObjectIterator(t *testing.T) {
}))
expectInt(t, idx, 4)
+ if c.headers == nil {
+ t.Error("ObjectIterator.Foreach did not initialize Container.Headers")
+ }
+
//test ForeachDetailed
+ c.Invalidate()
iter = c.Objects()
iter.Prefix = "schwift-test-listing"
idx = 0
@@ -115,6 +121,10 @@ func TestObjectIterator(t *testing.T) {
}))
expectInt(t, idx, 4)
+ if c.headers == nil {
+ t.Error("ObjectIterator.ForeachDetailed did not initialize Container.Headers")
+ }
+
//test Collect
iter = c.Objects()
iter.Prefix = "schwift-test-listing"