Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit d1c7d25

Browse files
Added cache-control header to objectstore
1 parent adc2065 commit d1c7d25

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

openstack/objectstorage/v1/objects/fixtures.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ func HandleCreateTextObjectSuccessfully(t *testing.T, content string) {
125125
})
126126
}
127127

128+
// HandleCreateTextWithCacheControlSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler
129+
// mux that responds with a `Create` response. A Cache-Control of `max-age="3600", public` is expected.
130+
func HandleCreateTextWithCacheControlSuccessfully(t *testing.T, content string) {
131+
th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
132+
th.TestMethod(t, r, "PUT")
133+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
134+
th.TestHeader(t, r, "Cache-Control", `max-age="3600", public`)
135+
th.TestHeader(t, r, "Accept", "application/json")
136+
137+
hash := md5.New()
138+
io.WriteString(hash, content)
139+
localChecksum := hash.Sum(nil)
140+
141+
w.Header().Set("ETag", fmt.Sprintf("%x", localChecksum))
142+
w.WriteHeader(http.StatusCreated)
143+
})
144+
}
145+
128146
// HandleCreateTypelessObjectSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler
129147
// mux that responds with a `Create` response. No Content-Type header may be present in the request, so that server-
130148
// side content-type detection will be triggered properly.

openstack/objectstorage/v1/objects/requests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ type CreateOptsBuilder interface {
155155
// CreateOpts is a structure that holds parameters for creating an object.
156156
type CreateOpts struct {
157157
Metadata map[string]string
158+
CacheControl string `h:"Cache-Control"`
158159
ContentDisposition string `h:"Content-Disposition"`
159160
ContentEncoding string `h:"Content-Encoding"`
160161
ContentLength int64 `h:"Content-Length"`

openstack/objectstorage/v1/objects/requests_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ func TestCreateObject(t *testing.T) {
9696
th.AssertNoErr(t, res.Err)
9797
}
9898

99+
func TestCreateObjectWithCacheControl(t *testing.T) {
100+
th.SetupHTTP()
101+
defer th.TeardownHTTP()
102+
103+
content := "All mimsy were the borogoves"
104+
105+
HandleCreateTextWithCacheControlSuccessfully(t, content)
106+
107+
options := &CreateOpts{CacheControl: `max-age="3600", public`}
108+
res := Create(fake.ServiceClient(), "testContainer", "testObject", strings.NewReader(content), options)
109+
th.AssertNoErr(t, res.Err)
110+
}
111+
99112
func TestCreateObjectWithoutContentType(t *testing.T) {
100113
th.SetupHTTP()
101114
defer th.TeardownHTTP()

0 commit comments

Comments
 (0)