Skip to content
Snippets Groups Projects
  • Akihiko Odaki's avatar
    40e5d230
    Validate HTTP response length while receiving (#6891) · 40e5d230
    Akihiko Odaki authored
    to_s method of HTTP::Response keeps blocking while it receives the whole
    content, no matter how it is big. This means it may waste time to receive
    unacceptably large files. It may also consume memory and disk in the
    process. This solves the inefficency by checking response length while
    receiving.
    40e5d230
    History
    Validate HTTP response length while receiving (#6891)
    Akihiko Odaki authored
    to_s method of HTTP::Response keeps blocking while it receives the whole
    content, no matter how it is big. This means it may waste time to receive
    unacceptably large files. It may also consume memory and disk in the
    process. This solves the inefficency by checking response length while
    receiving.
exceptions.rb 530 B
# frozen_string_literal: true

module Mastodon
  class Error < StandardError; end
  class NotPermittedError < Error; end
  class ValidationError < Error; end
  class HostValidationError < ValidationError; end
  class LengthValidationError < ValidationError; end
  class RaceConditionError < Error; end

  class UnexpectedResponseError < Error
    def initialize(response = nil)
      if response.respond_to? :uri
        super("#{response.uri} returned code #{response.code}")
      else
        super
      end
    end
  end
end