Class: Dimscan::HTTPByteEnumerator
- Inherits:
-
Object
- Object
- Dimscan::HTTPByteEnumerator
- Defined in:
- lib/dimscan/http_byte_enumerator.rb
Overview
A utility class for enumerating over the bytes of a http response body
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(url) ⇒ HTTPByteEnumerator
constructor
A new instance of HTTPByteEnumerator.
Constructor Details
#initialize(url) ⇒ HTTPByteEnumerator
Returns a new instance of HTTPByteEnumerator.
14 15 16 17 |
# File 'lib/dimscan/http_byte_enumerator.rb', line 14 def initialize(url) @uri = URI(url) fail ArgumentError, 'invalid scheme' unless @uri.scheme =~ /^https?$/ end |
Class Method Details
.http ⇒ Object
9 10 11 |
# File 'lib/dimscan/http_byte_enumerator.rb', line 9 def http @http ||= Net::HTTP::Persistent.new('dimscan') end |
Instance Method Details
#each(&block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dimscan/http_byte_enumerator.rb', line 19 def each(&block) return to_enum(__callee__) unless block_given? self.class.http.request(@uri) do |response| fail response.body if error?(response) enumerate_response(response, &block) end end |