Class: URLCanonicalize::BoundedBody

Inherits:
String
  • Object
show all
Defined in:
lib/url_canonicalize/bounded_body.rb

Overview

String-compatible response buffer that enforces a maximum byte size

Instance Method Summary collapse

Methods inherited from String

#canonicalize

Constructor Details

#initialize(max_bytes) ⇒ BoundedBody

Returns a new instance of BoundedBody.



6
7
8
9
# File 'lib/url_canonicalize/bounded_body.rb', line 6

def initialize(max_bytes)
  @max_bytes = max_bytes
  super()
end

Instance Method Details

#<<(chunk) ⇒ Object



11
12
13
14
15
# File 'lib/url_canonicalize/bounded_body.rb', line 11

def <<(chunk)
  raise URLCanonicalize::Exception::ResponseTooLarge, error_message if bytesize + chunk.bytesize > @max_bytes

  super
end