@@ -377,6 +377,28 @@ func Download(ctx *context.Context) {
377377		return 
378378	}
379379
380+ 	if  setting .Repository .StreamArchives  {
381+ 		downloadName  :=  ctx .Repo .Repository .Name  +  "-"  +  aReq .GetArchiveName ()
382+ 
383+ 		// Add nix format link header so tarballs lock correctly: 
384+ 		// https://github.com/nixos/nix/blob/56763ff918eb308db23080e560ed2ea3e00c80a7/doc/manual/src/protocols/tarball-fetcher.md 
385+ 		ctx .Resp .Header ().Add ("Link" , fmt .Sprintf (`<%s/archive/%s.%s?rev=%s>; rel="immutable"` ,
386+ 			ctx .Repo .Repository .APIURL (),
387+ 			aReq .CommitID ,
388+ 			aReq .Type .String (),
389+ 			aReq .CommitID ,
390+ 		))
391+ 
392+ 		ctx .SetServeHeaders (& context.ServeHeaderOptions {
393+ 			Filename : downloadName ,
394+ 		})
395+ 
396+ 		if  err  :=  aReq .Stream (ctx , ctx .Resp ); err  !=  nil  &&  ! ctx .Written () {
397+ 			ctx .ServerError ("archiver.StreamArchive" , err )
398+ 		}
399+ 		return 
400+ 	}
401+ 
380402	archiver , err  :=  aReq .Await (ctx )
381403	if  err  !=  nil  {
382404		ctx .ServerError ("archiver.Await" , err )
@@ -423,6 +445,12 @@ func download(ctx *context.Context, archiveName string, archiver *repo_model.Rep
423445// a request that's already in-progress, but the archiver service will just 
424446// kind of drop it on the floor if this is the case. 
425447func  InitiateDownload (ctx  * context.Context ) {
448+ 	if  setting .Repository .StreamArchives  {
449+ 		ctx .JSON (http .StatusOK , map [string ]any {
450+ 			"complete" : true ,
451+ 		})
452+ 		return 
453+ 	}
426454	aReq , err  :=  archiver_service .NewRequest (ctx .Repo .Repository .ID , ctx .Repo .GitRepo , ctx .PathParam ("*" ))
427455	if  err  !=  nil  {
428456		ctx .HTTPError (http .StatusBadRequest , "invalid archive request" )
0 commit comments