diff options
Diffstat (limited to 'app/models/lfs_download_object.rb')
-rw-r--r-- | app/models/lfs_download_object.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/lfs_download_object.rb b/app/models/lfs_download_object.rb index 6383f95d546..319499fd1b7 100644 --- a/app/models/lfs_download_object.rb +++ b/app/models/lfs_download_object.rb @@ -3,20 +3,32 @@ class LfsDownloadObject include ActiveModel::Validations - attr_accessor :oid, :size, :link + attr_accessor :oid, :size, :link, :headers delegate :sanitized_url, :credentials, to: :sanitized_uri validates :oid, format: { with: /\A\h{64}\z/ } validates :size, numericality: { greater_than_or_equal_to: 0 } validates :link, public_url: { protocols: %w(http https) } + validate :headers_must_be_hash - def initialize(oid:, size:, link:) + def initialize(oid:, size:, link:, headers: {}) @oid = oid @size = size @link = link + @headers = headers || {} end def sanitized_uri @sanitized_uri ||= Gitlab::UrlSanitizer.new(link) end + + def has_authorization_header? + headers.keys.map(&:downcase).include?('authorization') + end + + private + + def headers_must_be_hash + errors.add(:base, "headers must be a Hash") unless headers.is_a?(Hash) + end end |