summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-03-31 13:24:14 +0200
committerTomasz Maczukin <tomasz@maczukin.pl>2016-04-20 11:53:43 +0200
commit360bd831bfe40f3c44e35d884c32fa49fede87ab (patch)
treecac8e760eca76dd0cae8dd04091fda6f715c77e8 /lib
parent38a1378e631994ded578a6cfafd0648d22fdf263 (diff)
downloadgitlab-ce-360bd831bfe40f3c44e35d884c32fa49fede87ab.tar.gz
Add range checking
Diffstat (limited to 'lib')
-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