You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/services
zeripath 06f968d662
Fix hard-coded timeout and error panic in API archive download endpoint (#20925) (#21051)
Backport #20925

This commit updates the `GET /api/v1/repos/{owner}/{repo}/archive/{archive}`
endpoint which prior to this PR had a couple of issues.

1. The endpoint had a hard-coded 20s timeout for the archiver to complete after
   which a 500 (Internal Server Error) was returned to client. For a scripted
   API client there was no clear way of telling that the operation timed out and
   that it should retry.

2. Whenever the timeout _did occur_, the code used to panic. This was caused by
   the API endpoint "delegating" to the same call path as the web, which uses a
   slightly different way of reporting errors (HTML rather than JSON for
   example).

   More specifically, `api/v1/repo/file.go#GetArchive` just called through to
   `web/repo/repo.go#Download`, which expects the `Context` to have a `Render`
   field set, but which is `nil` for API calls. Hence, a `nil` pointer error.

The code addresses (1) by dropping the hard-coded timeout. Instead, any
timeout/cancelation on the incoming `Context` is used.

The code addresses (2) by updating the API endpoint to use a separate call path
for the API-triggered archive download. This avoids producing HTML-errors on
errors (it now produces JSON errors).

Signed-off-by: Peter Gardfjäll <peter.gardfjall.work@gmail.com>

Signed-off-by: Peter Gardfjäll <peter.gardfjall.work@gmail.com>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Peter Gardfjäll <peter.gardfjall.work@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2 years ago
..
agit move agit dependcy (#19998) 3 years ago
asymkey Move issues related files into models/issues (#19931) 3 years ago
attachment Move almost all functions' parameter db.Engine to context.Context (#19748) 3 years ago
auth EscapeFilter the group dn membership (#20200) (#20254) 3 years ago
automerge Move issues related files into models/issues (#19931) 3 years ago
comments Move issues related files into models/issues (#19931) 3 years ago
context Move almost all functions' parameter db.Engine to context.Context (#19748) 3 years ago
cron Move some code into models/git (#19879) 3 years ago
externalaccount
forms Move issues related files into models/issues (#19931) 3 years ago
gitdiff Remove legacy git code (ver < 2.0), fine tune markup tests (#19930) 3 years ago
issue Check if project has the same repository id with issue when assign project to issue (#20133) (#20188) 3 years ago
lfs Move some code into models/git (#19879) 3 years ago
mailer Move issues related files into models/issues (#19931) 3 years ago
migrations Add more checks in migration code (#21011) (#21050) 2 years ago
mirror Always try to fetch repo for mirrors (#19975) 3 years ago
org Move almost all functions' parameter db.Engine to context.Context (#19748) 3 years ago
packages Use correct context to get package content (#20673) (#20676) 3 years ago
pull Prevent 500 is head repo does not have PullRequest unit in IsUserAllowedToUpdate (#20839) (#20848) 2 years ago
release Add more checks in migration code (#21011) (#21050) 2 years ago
repository Fix hard-coded timeout and error panic in API archive download endpoint (#20925) (#21051) 2 years ago
task Use a more general (and faster) method to sanitize URLs with credentials (#19239) 3 years ago
user Move almost all functions' parameter db.Engine to context.Context (#19748) 3 years ago
webhook fix(telegram): fix link bot to release tag (#19830) 3 years ago
wiki Move some helper files out of models (#19355) 3 years ago