mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-03 19:27:29 +02:00
Add direct serving of package content (#25543)
Fixes #24723 Direct serving of content aka HTTP redirect is not mentioned in any of the package registry specs but lots of official registries do that so it should be supported by the usual clients.
This commit is contained in:
1 parent
f1cb461c1f
commit
c890454769
26 files changed
+195
-235
No files matched your search
@@ -6,6 +6,7 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -139,6 +140,42 @@ func TestPackageGeneric(t *testing.T) {
|
||||
req = NewRequest(t, "GET", url+"/dummy.bin")
|
||||
MakeRequest(t, req, http.StatusUnauthorized)
|
||||
})
|
||||
|
||||
t.Run("ServeDirect", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
if setting.Packages.Storage.Type != setting.MinioStorageType {
|
||||
t.Skip("Test skipped for non-Minio-storage.")
|
||||
return
|
||||
}
|
||||
|
||||
if !setting.Packages.Storage.MinioConfig.ServeDirect {
|
||||
old := setting.Packages.Storage.MinioConfig.ServeDirect
|
||||
defer func() {
|
||||
setting.Packages.Storage.MinioConfig.ServeDirect = old
|
||||
}()
|
||||
|
||||
setting.Packages.Storage.MinioConfig.ServeDirect = true
|
||||
}
|
||||
|
||||
req := NewRequest(t, "GET", url+"/"+filename)
|
||||
resp := MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
checkDownloadCount(3)
|
||||
|
||||
location := resp.Header().Get("Location")
|
||||
assert.NotEmpty(t, location)
|
||||
|
||||
resp2, err := (&http.Client{}).Get(location)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp2.StatusCode)
|
||||
|
||||
body, err := io.ReadAll(resp2.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, content, body)
|
||||
|
||||
checkDownloadCount(3)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user