Added cache-control header to objectstore
diff --git a/openstack/objectstorage/v1/objects/fixtures.go b/openstack/objectstorage/v1/objects/fixtures.go
index 7a6e6e1..d2ea18c 100644
--- a/openstack/objectstorage/v1/objects/fixtures.go
+++ b/openstack/objectstorage/v1/objects/fixtures.go
@@ -125,6 +125,24 @@
})
}
+// HandleCreateTextWithCacheControlSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler
+// mux that responds with a `Create` response. A Cache-Control of `max-age="3600", public` is expected.
+func HandleCreateTextWithCacheControlSuccessfully(t *testing.T, content string) {
+ th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Cache-Control", `max-age="3600", public`)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ hash := md5.New()
+ io.WriteString(hash, content)
+ localChecksum := hash.Sum(nil)
+
+ w.Header().Set("ETag", fmt.Sprintf("%x", localChecksum))
+ w.WriteHeader(http.StatusCreated)
+ })
+}
+
// HandleCreateTypelessObjectSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler
// mux that responds with a `Create` response. No Content-Type header may be present in the request, so that server-
// side content-type detection will be triggered properly.
diff --git a/openstack/objectstorage/v1/objects/requests.go b/openstack/objectstorage/v1/objects/requests.go
index f85add0..8c5d4bc 100644
--- a/openstack/objectstorage/v1/objects/requests.go
+++ b/openstack/objectstorage/v1/objects/requests.go
@@ -155,6 +155,7 @@
// CreateOpts is a structure that holds parameters for creating an object.
type CreateOpts struct {
Metadata map[string]string
+ CacheControl string `h:"Cache-Control"`
ContentDisposition string `h:"Content-Disposition"`
ContentEncoding string `h:"Content-Encoding"`
ContentLength int64 `h:"Content-Length"`
diff --git a/openstack/objectstorage/v1/objects/requests_test.go b/openstack/objectstorage/v1/objects/requests_test.go
index f7d6822..3a9d098 100644
--- a/openstack/objectstorage/v1/objects/requests_test.go
+++ b/openstack/objectstorage/v1/objects/requests_test.go
@@ -96,6 +96,19 @@
th.AssertNoErr(t, res.Err)
}
+func TestCreateObjectWithCacheControl(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ content := "All mimsy were the borogoves"
+
+ HandleCreateTextWithCacheControlSuccessfully(t, content)
+
+ options := &CreateOpts{CacheControl: `max-age="3600", public`}
+ res := Create(fake.ServiceClient(), "testContainer", "testObject", strings.NewReader(content), options)
+ th.AssertNoErr(t, res.Err)
+}
+
func TestCreateObjectWithoutContentType(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()