diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index ed554324..3759316c 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -14,7 +14,15 @@ class Travis::Api::App get '/:job_id/log' do resource = service(:find_artifact, params).run if !resource || resource.archived? - redirect archive_url("/jobs/#{params[:job_id]}/log.txt"), 307 + archived_log_path = archive_url("/jobs/#{params[:job_id]}/log.txt") + + if params[:cors_hax] + status 204 + headers['Access-Control-Expose-Headers'] = 'Location' + headers['Location'] = archived_log_path + else + redirect archived_log_path, 307 + end else respond_with resource end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index fa617d15..6df25881 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -40,5 +40,14 @@ describe 'Jobs' do response.should redirect_to("https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt") end end + + context 'with cors_hax param' do + it 'renders No Content response with location of the archived log' do + job.log.destroy + response = get "/jobs/#{job.id}/log.txt?cors_hax=true", {}, headers + response.status.should == 204 + response.headers['Location'].should == "https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt" + end + end end end