Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/ci/api
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-03-31 14:24:14 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2016-04-20 12:53:43 +0300
commit360bd831bfe40f3c44e35d884c32fa49fede87ab (patch)
treecac8e760eca76dd0cae8dd04091fda6f715c77e8 /lib/ci/api
parent38a1378e631994ded578a6cfafd0648d22fdf263 (diff)
Add range checking
Diffstat (limited to 'lib/ci/api')
-rw-r--r--lib/ci/api/api.rb2
-rw-r--r--lib/ci/api/builds.rb20
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/ci/api/api.rb b/lib/ci/api/api.rb
index 4e85d2c3c74..353c4ddebf8 100644
--- a/lib/ci/api/api.rb
+++ b/lib/ci/api/api.rb
@@ -23,6 +23,8 @@ module Ci
rack_response({ 'message' => '500 Internal Server Error' }, 500)
end
+ content_type :txt, 'text/plain'
+ content_type :json, 'application/json'
format :json
helpers ::Ci::API::Helpers
diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb
index 61e15675535..decee3739c8 100644
--- a/lib/ci/api/builds.rb
+++ b/lib/ci/api/builds.rb
@@ -51,12 +51,24 @@ module Ci
end
patch ":id/trace.txt" do
- authenticate_runner!
- update_runner_last_contact
- build = Ci::Build.where(runner_id: current_runner.id).running.find(params[:id])
+ build = Ci::Build.find_by_id(params[:id])
+ not_found! unless build
+ authenticate_build_token!(build)
forbidden!('Build has been erased!') if build.erased?
- build.append_trace(params[:trace_part])
+ error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range')
+ content_range = request.headers['Content-Range']
+ content_range = content_range.split('-')
+
+ unless build.trace_length == content_range[0].to_i
+ return error!('416 Range Not Satisfiable', 416, { 'Range' => "0-#{build.trace_length}" })
+ end
+
+ build.append_trace(request.body.read)
+
+ status 202
+ header 'Build-Status', build.status
+ header 'Range', "0-#{build.trace_length}"
end
# Authorize artifacts uploading for build - Runners only