s3api: answer a malformed Cache-Control on PutObject with InvalidRequest (#12733)

PutObject rejected a Cache-Control value it could not parse with
InvalidDigest, whose message is about Content-MD5, even when the request
sent no Content-MD5. CreateMultipartUpload already answers the same parse
error with InvalidRequest; PutObject now does too.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-18 11:03:57 -08:00
1 parent ebc77400ca
commit 94de65b3b5
2 files changed
+40 -1

No files matched your search

+1 -1
View File
@@ -147,7 +147,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
if r.Header.Get("Cache-Control") != "" {
if _, err = cacheobject.ParseRequestCacheControl(r.Header.Get("Cache-Control")); err != nil {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}
}
@@ -0,0 +1,39 @@
package s3api
import (
"net/http"
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
"github.com/stretchr/testify/require"
)
func TestPutObjectMalformedCacheControlIsInvalidRequest(t *testing.T) {
for _, value := range []string{"max-age=", "max-age=A", "public, max-age=abc"} {
t.Run(value, func(t *testing.T) {
s3a, filer, volume := newHeaderTestServer(t, "")
req, probe := newHeaderTestRequest("/b/o", "o", "hello world", "Cache-Control", value)
s3a.PutObjectHandler(probe, req)
requireRejected(t, probe, volume, s3err.ErrInvalidRequest)
filer.mu.Lock()
defer filer.mu.Unlock()
require.Empty(t, filer.entries)
})
}
}
func TestPutObjectStoresValidCacheControl(t *testing.T) {
s3a, filer, _ := newHeaderTestServer(t, "")
req, probe := newHeaderTestRequest("/b/o", "o", "hello world", "Cache-Control", "public, max-age=60")
s3a.PutObjectHandler(probe, req)
require.Equal(t, http.StatusOK, probe.Code, probe.Body.String())
filer.mu.Lock()
defer filer.mu.Unlock()
entry := filer.entries["/buckets/b/o"]
require.NotNil(t, entry)
require.Equal(t, "public, max-age=60", string(entry.Extended["Cache-Control"]))
}