http-cage 0.1.0
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 +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +12 -0
- data/http-cage.gemspec +25 -0
- data/lib/http-cage.rb +26 -0
- data/lib/http-cage/patch.rb +11 -0
- data/lib/http-cage/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07ccf37df58c4b6176f948d8c4175b859ef1ab95
|
4
|
+
data.tar.gz: 6bec2b5210760b7375e0a52730bfe41ea9572baa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2a69ddf90b50547b5a98de4e699d466d61ea87a9729c012eaf87d93e1e196ac40aa539992047b0028f5adee026d371662c67c0d99a28d4de3777cf90569f13f
|
7
|
+
data.tar.gz: b5b7485384a45b0b9a0697f0c97f39d96767b33348961ffa368beb0657551dcc36dd1c2ecacc1f65ac32b95bf2ab2a898feff62dd7f3d7e33f257b1819f8175f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 StickerMule, Marco Lisci
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# HTTP-Cage.
|
2
|
+
|
3
|
+
Global timeouts for Ruby's `Net::HTTP`.
|
4
|
+
|
5
|
+
## Why.
|
6
|
+
|
7
|
+
`Net::HTTP` by default has a connect timeout of 60 seconds and a request timeout of 60 seconds, a 2 minutes worst-case scenario timeout.
|
8
|
+
|
9
|
+
These defaults are kinda dangerous in a micro-services environment, where requests should happen fast or just timeout, to avoid server processes locking.
|
10
|
+
|
11
|
+
This gem lets you globally restrict timeouts of `Net::HTTP` calls, so that all gems and libraries that use `Net::HTTP` will timeout fast.
|
12
|
+
|
13
|
+
## Installation.
|
14
|
+
|
15
|
+
- Add it to your Gemfile:
|
16
|
+
```ruby
|
17
|
+
gem 'http-cage'
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
# Initialize the cage in your app initializer.
|
24
|
+
HTTPCage.timeout(connection: 3, request: 5)
|
25
|
+
|
26
|
+
# Increase global timeouts in a delayed job, for example.
|
27
|
+
HTTPCage.timeout(connection: 10, request: 30)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Test.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
bundle exec rake test:all
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contribute
|
37
|
+
|
38
|
+
- We use GitHub issues to discuss everything: features, bugs, docs.
|
39
|
+
- Before sending a pull request always open an issue.
|
40
|
+
|
41
|
+
## Maintainers
|
42
|
+
|
43
|
+
[badshark](https://github.com/badshark)
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
[MIT License](https://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/http-cage.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http-cage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http-cage"
|
8
|
+
spec.version = HTTPCage::VERSION
|
9
|
+
spec.authors = ["Marco Lisci"]
|
10
|
+
spec.email = ["marco@stickermule.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Global timeouts for Net::HTTP.}
|
13
|
+
spec.description = %q{Global timeouts for Net::HTTP.}
|
14
|
+
spec.homepage = "https://github.com/stickermule/http-cage"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|benchmarks)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
data/lib/http-cage.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'http-cage/version'
|
2
|
+
require 'http-cage/patch'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module HTTPCage
|
6
|
+
@connection = 60
|
7
|
+
@request = 60
|
8
|
+
|
9
|
+
def self.connection
|
10
|
+
@connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.request
|
14
|
+
@request
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.timeout(args)
|
18
|
+
@connection = args[:connection]
|
19
|
+
@request = args[:request]
|
20
|
+
apply
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.apply
|
24
|
+
Net::HTTP.prepend HTTPCage::Patch
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-cage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Lisci
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Global timeouts for Net::HTTP.
|
56
|
+
email:
|
57
|
+
- marco@stickermule.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- http-cage.gemspec
|
68
|
+
- lib/http-cage.rb
|
69
|
+
- lib/http-cage/patch.rb
|
70
|
+
- lib/http-cage/version.rb
|
71
|
+
homepage: https://github.com/stickermule/http-cage
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Global timeouts for Net::HTTP.
|
95
|
+
test_files: []
|