From c4496de8bf90ded13245fedc6b760805f15f6942 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin <godfat@godfat.org> Date: Thu, 14 Jul 2016 19:02:07 +0800 Subject: [PATCH] Provide the file directly rather than redirecting --- lib/api/builds.rb | 6 ++---- spec/requests/api/artifacts_spec.rb | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/api/builds.rb b/lib/api/builds.rb index 505ba1a66fe..5c14444f91a 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -69,9 +69,8 @@ module API authorize_read_builds! build = get_build!(params[:build_id]) - artifacts_file = build.artifacts_file - present_artifact!(artifacts_file) + present_artifact!(build.artifacts_file) end # Download the artifacts file from ref_name and build_name @@ -90,8 +89,7 @@ module API latest_build = builds.success.latest.first if latest_build - redirect( - "/projects/#{user_project.id}/builds/#{latest_build.id}/artifacts") + present_artifact!(latest_build.artifacts_file) else not_found! end diff --git a/spec/requests/api/artifacts_spec.rb b/spec/requests/api/artifacts_spec.rb index f1461f7bc53..56d0965b0be 100644 --- a/spec/requests/api/artifacts_spec.rb +++ b/spec/requests/api/artifacts_spec.rb @@ -31,10 +31,15 @@ describe API::API, api: true do it_behaves_like 'artifacts from ref with 404' end - context '302' do + context '200' do def verify - expect(response).to redirect_to( - "/projects/#{project.id}/builds/#{build.id}/artifacts") + download_headers = + { 'Content-Transfer-Encoding' => 'binary', + 'Content-Disposition' => + "attachment; filename=#{build.artifacts_file.filename}" } + + expect(response).to have_http_status(200) + expect(response.headers).to include(download_headers) end it_behaves_like 'artifacts from ref with 302' -- GitLab