forgejo/modules
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>
2022-09-06 07:54:47 +01:00
..
activitypub format with gofumpt (#18184) 2022-01-20 18:46:10 +01:00
analyze Simplify IsVendor (#19626) 2022-05-06 10:12:30 +01:00
appstate Use a struct as test options (#19393) 2022-04-14 21:58:21 +08:00
auth Remove legacy +build: constraint (#19582) 2022-05-02 23:22:45 +08:00
avatar Remove legacy +build: constraint (#19582) 2022-05-02 23:22:45 +08:00
base Prettify number of issues (#17760) 2022-06-12 20:08:23 +08:00
cache Update go-chi/cache to utilize Ping() (#19719) 2022-05-15 20:43:27 +02:00
charset Detect truncated utf-8 characters at the end of content as still representing utf-8 (#19773) 2022-05-21 14:06:24 +01:00
container Move reaction to models/issues/ (#19264) 2022-03-31 17:20:39 +08:00
context Fix download archiver of a commit (#20962) (#20971) 2022-08-28 13:29:34 +02:00
convert Fix 500 on time in timeline API (#21052) (#21057) 2022-09-04 16:12:37 +01:00
csv Allow render HTML with css/js external links (#19017) 2022-06-16 11:33:23 +08:00
doctor Fix git.Init for doctor sub-command (#20782) (#20783) 2022-08-14 00:32:44 +08:00
emoji format with gofumpt (#18184) 2022-01-20 18:46:10 +01:00
eventsource Stop spurious APIFormat stopwatches logs (#20008) 2022-06-17 22:47:15 +01:00
generate Use base32 for 2FA scratch token (#18384) 2022-01-26 12:10:10 +08:00
git Set uploadpack.allowFilter etc on gitea serv to enable partial clones with ssh (#20902) (#21058) 2022-09-04 12:17:27 -04:00
gitgraph Move some code into models/git (#19879) 2022-06-12 23:51:54 +08:00
graceful Ensure that graceful start-up is informed of unused SSH listener (#20877) 2022-08-21 20:18:22 +08:00
hcaptcha hCaptcha Support (#12594) 2020-10-02 23:37:53 -04:00
highlight Adjust line detection in highlight.go (#20612) 2022-08-03 01:37:28 +08:00
hostmatcher fix merge (#20819) 2022-08-17 11:33:26 -04:00
httpcache Add Cache-Control header to html and api responses, add no-transform (#20432) (#20459) 2022-07-23 11:58:58 +01:00
httplib refactor httplib (#18338) 2022-01-19 19:31:39 -05:00
indexer Fix dump-repo git init, fix wrong error type for NullDownloader (#20182) (#20186) 2022-07-01 18:01:05 +02:00
json Refactor legacy unknwon/com package, improve golangci lint (#19284) 2022-04-01 16:47:50 +08:00
lfs Move some code into models/git (#19879) 2022-06-12 23:51:54 +08:00
log Disable doctor logging on panic (#20847) (#20898) 2022-08-24 15:04:41 +01:00
markup Fix NPE when using non-numeric (#20277) (#20278) 2022-07-07 20:56:50 +08:00
metrics format with gofumpt (#18184) 2022-01-20 18:46:10 +01:00
migration Add more checks in migration code (#21011) (#21050) 2022-09-04 08:41:21 -05:00
nosql fix broken insecureskipverify handling in rediss connection uris (#20967) (#21053) 2022-09-04 14:59:20 +01:00
notification Move issues related files into models/issues (#19931) 2022-06-13 17:37:59 +08:00
options Remove legacy +build: constraint (#19582) 2022-05-02 23:22:45 +08:00
packages Add migrate repo archiver and packages storage support on command line (#20757) (#20806) 2022-08-18 09:27:56 +08:00
paginator Remove legacy unmaintained packages, refactor to support change default locale (#19308) 2022-04-03 17:46:48 +08:00
password Fixed assert statements. (#16089) 2021-06-07 07:27:09 +02:00
pprof refactor: move from io/ioutil to io and os package (#17109) 2021-09-22 13:38:34 +08:00
private Add Goroutine stack inspector to admin/monitor (#19207) 2022-03-31 19:01:43 +02:00
process Set Setpgid on child git processes (#19865) 2022-06-03 15:36:18 +01:00
proxy Return nil proxy function if proxy not enabled (#16742) 2021-08-19 16:41:20 -04:00
public Remove legacy +build: constraint (#19582) 2022-05-02 23:22:45 +08:00
queue Fix 64-bit atomic operations on 32-bit machines (#19531) 2022-04-27 10:32:04 -05:00
recaptcha refactor: move from io/ioutil to io and os package (#17109) 2021-09-22 13:38:34 +08:00
references Custom regexp external issues (#17624) 2022-06-10 13:39:53 +08:00
regexplru Custom regexp external issues (#17624) 2022-06-10 13:39:53 +08:00
repository Executable check always returns true for windows (#20637) (#20835) 2022-08-17 23:34:29 +01:00
secret Use CryptoRandomBytes instead of CryptoRandomString (#18439) 2022-02-04 18:03:15 +01:00
session format with gofumpt (#18184) 2022-01-20 18:46:10 +01:00
setting Enable contenthash in filename for dynamic assets (#20813) (#20932) 2022-08-25 07:16:20 +01:00
ssh Ensure that graceful start-up is informed of unused SSH listener (#20877) 2022-08-21 20:18:22 +08:00
storage Add Package Registry (#16510) 2022-03-30 16:42:47 +08:00
structs Dismiss prior pull reviews if done via web in review dismiss (#20197) (#20407) 2022-07-19 17:46:33 +02:00
svg Remove legacy +build: constraint (#19582) 2022-05-02 23:22:45 +08:00
sync Use queue instead of memory queue in webhook send service (#19390) 2022-04-25 20:03:01 +02:00
templates Enable contenthash in filename for dynamic assets (#20813) (#20932) 2022-08-25 07:16:20 +01:00
test Move access and repo permission to models/perm/access (#19350) 2022-05-11 12:09:36 +02:00
timeutil Fix hard-coded timeout and error panic in API archive download endpoint (#20925) (#21051) 2022-09-06 07:54:47 +01:00
translation Remove legacy unmaintained packages, refactor to support change default locale (#19308) 2022-04-03 17:46:48 +08:00
typesniffer Rework raw file http header logic (#20484) (#20542) 2022-07-30 18:37:02 +02:00
updatechecker format with gofumpt (#18184) 2022-01-20 18:46:10 +01:00
upload Simplify parameter types (#18006) 2021-12-20 04:41:31 +00:00
uri Prevent NPE if gitea uploader fails to open url (#18080) 2021-12-23 16:27:33 +00:00
user Add gitea-vet (#10948) 2020-04-05 07:20:50 +01:00
util Fix SecToTime edge-cases (#20610) (#20611) 2022-08-08 13:09:12 +08:00
validation Add more checks in migration code (#21011) (#21050) 2022-09-04 08:41:21 -05:00
web Unify repo settings & show better error (#19828) 2022-06-12 13:43:27 +08:00