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

Commit

Permalink
Merge pull request #586 from rodrigolourenco/cache-control-objectStore
Browse files Browse the repository at this point in the history
Added cache-control header to objectstore
  • Loading branch information
jrperritt committed Jun 3, 2016
2 parents 934dbf8 + c8f234b commit 2790196
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions openstack/objectstorage/v1/objects/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ func HandleCreateTextObjectSuccessfully(t *testing.T, content string) {
})
}

// 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.
Expand Down
1 change: 1 addition & 0 deletions openstack/objectstorage/v1/objects/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type CreateOptsBuilder interface {
// 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"`
Expand Down
13 changes: 13 additions & 0 deletions openstack/objectstorage/v1/objects/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ func TestCreateObject(t *testing.T) {
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()
Expand Down

0 comments on commit 2790196

Please sign in to comment.