Skip to content

Commit

Permalink
[api] do not read the post body unless we have to for validate
Browse files Browse the repository at this point in the history
This reduces memory usage for chromium commits - at least I hope so
  • Loading branch information
coolo committed Dec 18, 2013
1 parent be72a84 commit 7661b7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,21 @@ def self.validate_action(opt)
end
end

class LazyRequestReader
def initialize(req)
@req = req
end
def to_s
@req.raw_post
end
end

def validate_xml_request(method = nil)
opt = params()
opt[:method] = method || request.method.to_s
opt[:type] = 'request'
logger.debug "Validate XML request: #{request}"
Suse::Validator.validate(opt, request.raw_post.to_s)
Suse::Validator.validate(opt, LazyRequestReader.new(request))
end

def validate_xml_response
Expand Down
1 change: 0 additions & 1 deletion src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class IllegalRequest < APIException
validate_action update_project_meta: { request: :project, response: :status}
validate_action update_package_meta: { request: :package, response: :status}

skip_before_action :validate_xml_request, :only => [:file]
skip_before_action :extract_user, only: [:lastevents_public]

before_action :require_valid_project_name, except: [:index, :lastevents, :lastevents_public, :global_command]
Expand Down
1 change: 1 addition & 0 deletions src/api/lib/opensuse/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def validate(opt, content)
if content.nil?
raise "illegal option; need content for #{schema_base_filename}"
end
content = content.to_s
if content.empty?
logger.debug "no content, skipping validation for #{schema_file}"
raise ValidationError, "Document is empty, not allowed for #{schema_base_filename}"
Expand Down

0 comments on commit 7661b7f

Please sign in to comment.