@@ -307,6 +307,23 @@ func archiveDownload(ctx *context.APIContext) {
307307		return 
308308	}
309309
310+ 	downloadName  :=  prepareDownload (ctx , aReq )
311+ 
312+ 	if  setting .Repository .StreamArchives  {
313+ 		streamDownload (ctx , downloadName , aReq )
314+ 		return 
315+ 	}
316+ 
317+ 	archiver , err  :=  aReq .Await (ctx )
318+ 	if  err  !=  nil  {
319+ 		ctx .APIErrorInternal (err )
320+ 		return 
321+ 	}
322+ 
323+ 	download (ctx , downloadName , archiver )
324+ }
325+ 
326+ func  prepareDownload (ctx  * context.APIContext , aReq  * archiver_service.ArchiveRequest ) (downloadName  string ) {
310327	// Add nix format link header so tarballs lock correctly: 
311328	// https://github.com/nixos/nix/blob/56763ff918eb308db23080e560ed2ea3e00c80a7/doc/manual/src/protocols/tarball-fetcher.md 
312329	ctx .Resp .Header ().Add ("Link" , fmt .Sprintf (`<%s/archive/%s.%s?rev=%s>; rel="immutable"` ,
@@ -316,26 +333,17 @@ func archiveDownload(ctx *context.APIContext) {
316333		aReq .CommitID ,
317334	))
318335
319- 	downloadName  :=  ctx .Repo .Repository .Name  +  "-"  +  aReq .GetArchiveName ()
320- 
321- 	if  setting .Repository .StreamArchives  {
322- 		ctx .SetServeHeaders (& context.ServeHeaderOptions {
323- 			Filename : downloadName ,
324- 		})
336+ 	return  ctx .Repo .Repository .Name  +  "-"  +  aReq .GetArchiveName ()
337+ }
325338
326- 		if  err  :=  aReq .Stream (ctx , ctx .Repo .GitRepo , ctx .Resp ); err  !=  nil  &&  ! ctx .Written () {
327- 			ctx .APIErrorInternal (err )
328- 		}
329- 		return 
330- 	}
339+ func  streamDownload (ctx  * context.APIContext , downloadName  string , r  * archiver_service.ArchiveRequest ) {
340+ 	ctx .SetServeHeaders (& context.ServeHeaderOptions {
341+ 		Filename : downloadName ,
342+ 	})
331343
332- 	archiver , err  :=  aReq .Await (ctx )
333- 	if  err  !=  nil  {
344+ 	if  err  :=  r .Stream (ctx , ctx .Repo .GitRepo , ctx .Resp ); err  !=  nil  &&  ! ctx .Written () {
334345		ctx .APIErrorInternal (err )
335- 		return 
336346	}
337- 
338- 	download (ctx , downloadName , archiver )
339347}
340348
341349func  download (ctx  * context.APIContext , downloadName  string , archiver  * repo_model.RepoArchiver ) {
0 commit comments