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:
Gusted 2025-02-19 15:40:27 +01:00
parent d81baf21e9
commit f41d20ec67
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 9 additions and 1 deletions

View file

@ -1143,7 +1143,7 @@ func Routes() *web.Route {
Put(reqAdmin(), repo.AddTeam).
Delete(reqAdmin(), repo.DeleteTeam)
}, 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("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
if !setting.Repository.DisableForks {