api_hammer 0.16.0 → 0.17.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/bin/hc +1 -1
- data/gemfiles/Gemfile_rack_1 +4 -0
- data/gemfiles/Gemfile_rack_2 +4 -0
- data/lib/api_hammer/show_text_exceptions.rb +14 -1
- data/lib/api_hammer/sinatra.rb +10 -6
- data/lib/api_hammer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d812135b67bb320c645f0adaa2a50384f7c4e81b
|
|
4
|
+
data.tar.gz: 3f8c644149a7ad7878d50af7dd1fb2fbd4ce1166
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f06fc026f7cc0383eed1ac89974dab0e1d3d9d6067a0d4c95d09c8397f7cbfd825e201c5a4720fc097d3099091d232a7e80e29fce20d2c45ca07eb6fdfa23fc1
|
|
7
|
+
data.tar.gz: 3400cc586418fc47faffd6462f78626229d84361f703c9675f6af44978633629aa3104665f1618f11fd33f7480d5a22cc71a2035e463e4e3716946463e9f433c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# v0.17.0
|
|
2
|
+
- fix ApiHammer::ShowTextExceptions middleware to not rescue certain exceptions
|
|
3
|
+
- don't insert or rely on Rack::Accept middleware for sinatra; use Rack::Accept more directly
|
|
4
|
+
- improve hc User-Agent
|
|
5
|
+
|
|
1
6
|
# v0.16.0
|
|
2
7
|
- fix dependency on json pure parser, which moved from the json gem to json_pure gem
|
|
3
8
|
|
data/Gemfile
CHANGED
data/bin/hc
CHANGED
|
@@ -123,7 +123,7 @@ if body && !headers['Content-Type'.downcase]
|
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
unless headers.keys.any? { |key| key.downcase == 'user-agent' }
|
|
126
|
-
headers['User-Agent'] = "ApiHammer
|
|
126
|
+
headers['User-Agent'] = "ApiHammer-hc/#{ApiHammer::VERSION} (#{RUBY_ENGINE} #{RUBY_VERSION}; #{RUBY_PLATFORM})"
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
# OH LOOK IT'S FINALLY ACTUALLY CONNECTING TO SOMETHING
|
data/gemfiles/Gemfile_rack_1
CHANGED
data/gemfiles/Gemfile_rack_2
CHANGED
|
@@ -9,6 +9,19 @@ module ApiHammer
|
|
|
9
9
|
# those middlewares have a #prefers_plain_text? method which makes them behave like this, but
|
|
10
10
|
# it's simpler and more reliable to roll our own than monkey-patch those)
|
|
11
11
|
class ShowTextExceptions
|
|
12
|
+
# this module blatantly stolen from
|
|
13
|
+
# https://github.com/rspec/rspec-support/blob/v3.5.0/lib/rspec/support.rb#L121-L130
|
|
14
|
+
# under MIT license https://github.com/rspec/rspec-support/blob/v3.5.0/LICENSE.md
|
|
15
|
+
module AllExceptionsExceptOnesWeMustNotRescue
|
|
16
|
+
# These exceptions are dangerous to rescue as rescuing them
|
|
17
|
+
# would interfere with things we should not interfere with.
|
|
18
|
+
AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]
|
|
19
|
+
|
|
20
|
+
def self.===(exception)
|
|
21
|
+
AVOID_RESCUING.none? { |ar| ar === exception }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
12
25
|
def initialize(app, options)
|
|
13
26
|
@app=app
|
|
14
27
|
@options = options
|
|
@@ -16,7 +29,7 @@ module ApiHammer
|
|
|
16
29
|
def call(env)
|
|
17
30
|
begin
|
|
18
31
|
@app.call(env)
|
|
19
|
-
rescue
|
|
32
|
+
rescue AllExceptionsExceptOnesWeMustNotRescue => e
|
|
20
33
|
full_error_message = (["#{e.class}: #{e.message}"] + e.backtrace.map{|l| " #{l}" }).join("\n")
|
|
21
34
|
if @options[:logger]
|
|
22
35
|
@options[:logger].error(full_error_message)
|
data/lib/api_hammer/sinatra.rb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
require 'api_hammer/sinatra/halt'
|
|
2
|
+
begin
|
|
3
|
+
require 'rack/accept'
|
|
4
|
+
rescue LoadError => e
|
|
5
|
+
raise e.class, e.message + "\nPlease `gem install rack_accept` or add rack_accept to your Gemfile", e.backtrace
|
|
6
|
+
end
|
|
2
7
|
|
|
3
8
|
module ApiHammer
|
|
4
9
|
module Sinatra
|
|
@@ -27,10 +32,6 @@ module ApiHammer
|
|
|
27
32
|
use middleware, *args, &block
|
|
28
33
|
use Rack::Lint if development? || test?
|
|
29
34
|
end
|
|
30
|
-
|
|
31
|
-
# ApiHammer::Sinatra's methods use Rack::Accept so we will go ahead and put this middleware
|
|
32
|
-
# in the stack
|
|
33
|
-
klass.use_with_lint Rack::Accept
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
@@ -60,10 +61,11 @@ module ApiHammer
|
|
|
60
61
|
# returns the first supported media type.
|
|
61
62
|
def response_media_type(options={})
|
|
62
63
|
options = {:halt_if_unacceptable => false}.merge(options)
|
|
64
|
+
env = options[:env] || (respond_to?(:env) ? self.env : raise(ArgumentError, "must pass env"))
|
|
63
65
|
accept = env['HTTP_ACCEPT']
|
|
64
66
|
if accept =~ /\S/
|
|
65
67
|
begin
|
|
66
|
-
best_media_type = env
|
|
68
|
+
best_media_type = Rack::Accept::Request.new(env).best_media_type(supported_media_types)
|
|
67
69
|
rescue RuntimeError => e
|
|
68
70
|
# TODO: this is a crappy way to recognize this exception
|
|
69
71
|
raise unless e.message =~ /Invalid header value/
|
|
@@ -83,8 +85,10 @@ module ApiHammer
|
|
|
83
85
|
supported_media_types.first
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
|
-
|
|
88
|
+
elsif supported_media_types && supported_media_types.any?
|
|
87
89
|
supported_media_types.first
|
|
90
|
+
else
|
|
91
|
+
raise "No media types are defined. Please set supported_media_types."
|
|
88
92
|
end
|
|
89
93
|
end
|
|
90
94
|
|
data/lib/api_hammer/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api_hammer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ethan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-04-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -305,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
305
305
|
version: '0'
|
|
306
306
|
requirements: []
|
|
307
307
|
rubyforge_project:
|
|
308
|
-
rubygems_version: 2.
|
|
308
|
+
rubygems_version: 2.6.11
|
|
309
309
|
signing_key:
|
|
310
310
|
specification_version: 4
|
|
311
311
|
summary: an API tool
|