immosquare-constants 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acd5cacc9574f861e591cc7fda32c3f01e65ef177135b4ca4d6f3a5f1c9baf5b
4
- data.tar.gz: 4e2327a62218077cc231b487d48924640dba9ce5567df5eceb4cc4dfe41274d4
3
+ metadata.gz: 6098bdf582ab7d9829fc6e29756d68ef26001a9afdfcfa87b8ad0e3bc3ea2849
4
+ data.tar.gz: 27aef060a5800c610d82e66adefe8fc6337311b6bb66c0fa9188099aec589887
5
5
  SHA512:
6
- metadata.gz: 63ea9d8d4da820c89cff4d3d611c2d77be3598c37dbd2fa49fe02d54581d26f2d2b73df2ae2059b1b316f6ba7b66f738aaace6ae89ca8e33cfbe63cfe16ed400
7
- data.tar.gz: ba8dee9159df1505ccbd384a23b3800af81c396ca72862b58a0fae4855350f8974b9c816d1315e5b887f82f7ff66db9ca4c7dc362f1c914a85fcba416f425053
6
+ metadata.gz: fb9cc95875219727e1780a8d5cb4e6dfb511ba17a523302e73530b603039e087689b96e040fef396300e7a61a42eec660027cec3ec727b4c5624ff668fc963a7
7
+ data.tar.gz: 12e6b70b66597ac332c504a760a7747d099b1df954690447abcb0046f92431d018dee74d93b363ea95a5c67d79f863f5812d96bd0401c45181bcda5265bdbb6c
@@ -6,6 +6,7 @@ require "resolv"
6
6
 
7
7
  module ImmosquareConstants
8
8
  module Ip
9
+ PUBLIC_IP_TIMEOUT = 2
9
10
  ##============================================================##
10
11
  ## Simple class to provide dot notation access to IP addresses
11
12
  ##============================================================##
@@ -159,14 +160,21 @@ module ImmosquareConstants
159
160
 
160
161
  ##============================================================##
161
162
  ## Get public IP address with fallback
163
+ ##
164
+ ## Callers run inside web requests (Rack middlewares): without
165
+ ## explicit timeouts, Net::HTTP waits up to 60s to connect and
166
+ ## 60s to read, so a slow checkip endpoint would hold a server
167
+ ## thread for two minutes per request.
162
168
  ##============================================================##
163
169
  def get_public_ip_from_aws
164
170
  begin
165
171
  begin
166
- uri = URI.parse("https://checkip.amazonaws.com/")
167
- http = Net::HTTP.new(uri.host, uri.port)
168
- http.use_ssl = true
169
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
172
+ uri = URI.parse("https://checkip.amazonaws.com/")
173
+ http = Net::HTTP.new(uri.host, uri.port)
174
+ http.use_ssl = true
175
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
176
+ http.open_timeout = PUBLIC_IP_TIMEOUT
177
+ http.read_timeout = PUBLIC_IP_TIMEOUT
170
178
  response = http.get(uri.request_uri)
171
179
  raise("No IP found") if !response.is_a?(Net::HTTPSuccess)
172
180
 
@@ -1,3 +1,3 @@
1
1
  module ImmosquareConstants
2
- VERSION = "0.1.17".freeze
2
+ VERSION = "0.1.18".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-constants
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
- rubygems_version: 4.0.10
44
+ rubygems_version: 4.0.21
45
45
  specification_version: 4
46
46
  summary: ImmosquareConstants is a comprehensive collection of constants useful for
47
47
  a variety of applications.