dimscan 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd65bee04e3ac2eb21714d2960ffa0071b6f05eb
4
- data.tar.gz: f2fb30053e3140b8c2903137f55737fabb8cd9fe
3
+ metadata.gz: 7d23ddb35aeff44c2ee1146b91d8b9b909bccbf9
4
+ data.tar.gz: d5e250c9f69895d437337cbc733b6c8a1687cb49
5
5
  SHA512:
6
- metadata.gz: 32fbd18f4b5b91294c189090c7ea71eabdcf42efcaad742f4274faf6601f48cb15efba3436b5f42860c3f44ce33e7055a6ad7ae3825c83b3db6c39bf70706505
7
- data.tar.gz: 76f6a8d83c7a5d11bca9ddd4ae52aee02f3d6e07bd46453f5820485fe55297d3d4d191442e3935138b2159c938dcfaa8558285ca816f04fcaa9a2aa1b40a10e5
6
+ metadata.gz: c12df6b388957fdf2867a44e86851acdfa39b41bc3e219af5fdb929735aef914ba8c207e9415e4db64e8e5439739f0b97dbaa4b43fe45ea988b98f327d2d8897
7
+ data.tar.gz: 78ccee05a9a10ea415fb4104d61c9cf14a774eeaccc40c56917384332dc425b87f9a2c5ae86ad72da1e0467564c1ac1c62ad562f0ae660f61fcdbc139819ace4
@@ -1,6 +1,12 @@
1
1
  require 'dimscan/version'
2
2
  require 'dimscan/jpeg_scanner'
3
3
  require 'dimscan/png_scanner'
4
+ require 'dimscan/http_byte_enumerator'
4
5
 
5
6
  module Dimscan
7
+ class << self
8
+ def close_connections
9
+ HTTPByteEnumerator.close_connections
10
+ end
11
+ end
6
12
  end
@@ -4,6 +4,25 @@ require 'net/http'
4
4
  module Dimscan
5
5
  # A utility class for enumerating over the bytes of a http response body
6
6
  class HTTPByteEnumerator
7
+ @connections = {}
8
+ class << self
9
+ def open_connection(host, port, ssl)
10
+ @connections[host] ||= {}
11
+ @connections[host][port] ||= {}
12
+ @connections[host][port][ssl] ||= Net::HTTP.start(
13
+ host, port, use_ssl: ssl
14
+ )
15
+ end
16
+
17
+ def close_connections
18
+ @connections.values.each do |ports|
19
+ ports.values.each do |connections|
20
+ connections.values.each(&:finish)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
7
26
  def initialize(url)
8
27
  @uri = URI(url)
9
28
  fail ArgumentError, 'invalid scheme' unless @uri.scheme =~ /^https?$/
@@ -12,13 +31,12 @@ module Dimscan
12
31
  def each(&block)
13
32
  return to_enum(__callee__) unless block_given?
14
33
  request = Net::HTTP::Get.new(@uri)
15
- Net::HTTP.start(
16
- @uri.host, @uri.port, use_ssl: @uri.scheme == 'https'
17
- ) do |http|
18
- http.request(request) do |response|
19
- fail response.body if error?(response)
20
- enumerate_response(response, &block)
21
- end
34
+ http = self.class.open_connection(
35
+ @uri.host, @uri.port, @uri.scheme == 'https'
36
+ )
37
+ http.request(request) do |response|
38
+ fail response.body if error?(response)
39
+ enumerate_response(response, &block)
22
40
  end
23
41
  end
24
42
 
@@ -1,4 +1,4 @@
1
1
  # Version string
2
2
  module Dimscan
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Reinert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler