mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-03 13:20:28 +00:00
feat: Allow HEAD /repos/{owner}/{repo}/raw/{filepath}
- Make the API route `/repos/{owner}/{repo}/raw/{filepath}` accept `HEAD` as a method, this can then be used to confirm if a specific file exists or not. - Resolves forgejo/forgejo#6992 - Added integration test.
This commit is contained in:
parent
d81baf21e9
commit
f41d20ec67
2 changed files with 9 additions and 1 deletions
|
@ -1143,7 +1143,7 @@ func Routes() *web.Route {
|
||||||
Put(reqAdmin(), repo.AddTeam).
|
Put(reqAdmin(), repo.AddTeam).
|
||||||
Delete(reqAdmin(), repo.DeleteTeam)
|
Delete(reqAdmin(), repo.DeleteTeam)
|
||||||
}, reqToken())
|
}, reqToken())
|
||||||
m.Get("/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
|
m.Methods("GET,HEAD", "/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
|
||||||
m.Get("/media/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFileOrLFS)
|
m.Get("/media/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFileOrLFS)
|
||||||
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
|
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
|
||||||
if !setting.Repository.DisableForks {
|
if !setting.Repository.DisableForks {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -192,5 +193,12 @@ func TestAPIGetContentsRefFormats(t *testing.T) {
|
||||||
raw, err = io.ReadAll(resp.Body)
|
raw, err = io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, content, string(raw))
|
assert.EqualValues(t, content, string(raw))
|
||||||
|
|
||||||
|
t.Run("HEAD request", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
MakeRequest(t, NewRequest(t, http.MethodHead, noRef), http.StatusOK)
|
||||||
|
MakeRequest(t, NewRequest(t, http.MethodHead, "api/v1/repos/user2/repo1/raw/file-does-not-exist"), http.StatusNotFound)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue