http: add basic metadata and provide it via serve
Some checks failed
build / windows (push) Has been cancelled
build / other_os (push) Has been cancelled
build / mac_amd64 (push) Has been cancelled
build / mac_arm64 (push) Has been cancelled
build / linux (push) Has been cancelled
build / go1.24 (push) Has been cancelled
build / linux_386 (push) Has been cancelled
build / lint (push) Has been cancelled
build / android-all (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/386 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/amd64 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v6 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v7 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm64 (push) Has been cancelled
Build & Push Docker Images / Merge & Push Final Docker Image (push) Has been cancelled

Co-authored-by: dougal <147946567+roucc@users.noreply.github.com>
This commit is contained in:
Oleg Kunitsyn
2025-11-17 17:52:30 +01:00
committed by GitHub
parent 80e6389a50
commit ecea0cd6f9
9 changed files with 232 additions and 12 deletions

View File

@@ -8,6 +8,8 @@ import (
"testing"
"time"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/object"
"github.com/rclone/rclone/fstest/mockobject"
"github.com/stretchr/testify/assert"
)
@@ -82,3 +84,23 @@ func TestObjectBadRange(t *testing.T) {
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, "Bad Request\n", string(body))
}
func TestObjectHEADMetadata(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest("HEAD", "http://example.com/aFile", nil)
m := fs.Metadata{
"content-disposition": "inline",
"cache-control": "no-cache",
"content-language": "en",
"content-encoding": "gzip",
}
o := object.NewMemoryObject("aFile", time.Now(), []byte("")).
WithMetadata(m).WithMimeType("text/plain; charset=utf-8")
Object(w, r, o)
resp := w.Result()
assert.Equal(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))
assert.Equal(t, "inline", resp.Header.Get("Content-Disposition"))
assert.Equal(t, "no-cache", resp.Header.Get("Cache-Control"))
assert.Equal(t, "en", resp.Header.Get("Content-Language"))
assert.Equal(t, "gzip", resp.Header.Get("Content-Encoding"))
}