class ImageInfo::RequestHandler

Attributes

buffer[R]
image[R]

Public Class Methods

new(image) click to toggle source
# File lib/image_info/request_handler.rb, line 7
def initialize(image)
  @image = image
  @buffer = StringIO.new
end

Public Instance Methods

build() click to toggle source
# File lib/image_info/request_handler.rb, line 12
def build
  ::Typhoeus::Request.new(image.uri.to_s, followlocation: true, accept_encoding: :gzip).tap do |request|
    request.on_body do |chunk|
      buffer.write(chunk)
      buffer.rewind
      :abort if max_image_size_reached? || found_image_info?
    end
  end
end

Private Instance Methods

found_image_info?() click to toggle source
# File lib/image_info/request_handler.rb, line 24
def found_image_info?
  ::ImageInfo::Parser.new(image, buffer).call
end
max_image_size() click to toggle source
# File lib/image_info/request_handler.rb, line 34
def max_image_size
  ::ImageInfo.config.max_image_size
end
max_image_size_reached?() click to toggle source
# File lib/image_info/request_handler.rb, line 28
def max_image_size_reached?
  return false if max_image_size <= 0

  buffer.size > max_image_size
end