rack-logstash-writer 1.2.0 → 1.2.1
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/lib/rack/logstash-writer.rb +17 -7
- data/lib/rack/logstash-writer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66afeb37c4348d48af51b1886a3cea76d33cd1b4
|
4
|
+
data.tar.gz: 159a1232bcd83a11645e972949051fb5caa4b3ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9adab0adf71ef461fb169b2b5759d67284647dca416ef6d2750438702d4e90c1716002bfa81189d1b760a2102ffe77c92e87c493503f55f3989b1715271c59f
|
7
|
+
data.tar.gz: 70bc7d2aae4990efd783cd0d8a74ddecdeed99db50589bebdd963643305001d1797c02cf62d2edcb562fabd1e86568dc044963578e754440d9c5789b1881593c
|
data/lib/rack/logstash-writer.rb
CHANGED
@@ -14,8 +14,14 @@ module Rack
|
|
14
14
|
add_request_script?: false,
|
15
15
|
curl_opts: {}
|
16
16
|
}
|
17
|
-
CURL_DEFAULT_OPTS = {data_proc: proc(&:to_json), ignored_headers: [], verbose?: true}
|
18
17
|
REQUIRED_OPTIONS = [:url]
|
18
|
+
CURL_DEFAULT_OPTS = {
|
19
|
+
data_key: 'rack.request.form_hash',
|
20
|
+
data_proc: proc(&:to_json),
|
21
|
+
ignored_headers: [],
|
22
|
+
verbose: true
|
23
|
+
}
|
24
|
+
COMMON_ENCODINGS = %w(compress deflate exi gzip pack200-gzip br)
|
19
25
|
|
20
26
|
# Initialize a new Rack adapter, logstash writer
|
21
27
|
# @param [Proc] app
|
@@ -102,7 +108,7 @@ module Rack
|
|
102
108
|
|
103
109
|
# add curl if users enables it
|
104
110
|
if @options[:add_curl_command?] || @options[:add_request_script?]
|
105
|
-
data[:curl] = gen_curl_by_rack_env(env, CURL_DEFAULT_OPTS.merge(@options[:curl_opts]))
|
111
|
+
data[:curl] = gen_curl_by_rack_env(env, response_headers, CURL_DEFAULT_OPTS.merge(@options[:curl_opts]))
|
106
112
|
end
|
107
113
|
|
108
114
|
# This just works for all body types (magic?)... see http://www.rubydoc.info/github/rack/rack/Rack/BodyProxy
|
@@ -159,15 +165,16 @@ module Rack
|
|
159
165
|
# * @option [Proc] :data_proc: for processing the data prior for inserting it to query (by --data flag)
|
160
166
|
# * @option [Array<String>] :ignored_headers: to prevent inclusion to the query (by --header flag)
|
161
167
|
# * @option [Array<String>] :extra_arguments: string ot args to add to the query
|
162
|
-
# * @option [Boolean] :verbose
|
168
|
+
# * @option [Boolean] :verbose: add --verbose switch if true. default: true
|
169
|
+
# * @option [Boolean] :compressed: add or exclude --compressed switch by force. default: chooses automatically.
|
163
170
|
# @return [String] of curl unix-command that will imitate the request to server/service
|
164
|
-
def gen_curl_by_rack_env env, opts
|
171
|
+
def gen_curl_by_rack_env env, response_headers, opts
|
165
172
|
command_acc = ["curl #{url(env)} "]
|
166
173
|
|
167
174
|
command_acc << "--request #{env['REQUEST_METHOD']}"
|
168
175
|
|
169
176
|
# form-data will be processed by the proc sent by the user
|
170
|
-
data = opts[:data_proc].call(env[
|
177
|
+
data = opts[:data_proc].call(env[opts[:data_key]]) rescue env['rack.request.form_hash']
|
171
178
|
command_acc << "--data #{data.inspect}" if data && !data.empty?
|
172
179
|
|
173
180
|
# add all headers to the query. do not add +ignore_headers+ specified by the user
|
@@ -182,6 +189,8 @@ module Rack
|
|
182
189
|
|
183
190
|
# the curl script is intended for debugging, therefore --verbose switch is added (unless specified by caller)
|
184
191
|
command_acc << '--verbose' if opts[:verbose]
|
192
|
+
encodings = response_headers['Content-Encoding'].to_s.split(',').map(&:strip) & COMMON_ENCODINGS
|
193
|
+
command_acc << '--compressed' if (opts[:compressed].nil? ? !encodings.empty? : opts[:compressed])
|
185
194
|
|
186
195
|
# let user change the query as they desire
|
187
196
|
command_acc += opts[:extra_arguments] if opts[:extra_arguments]
|
@@ -191,10 +200,11 @@ module Rack
|
|
191
200
|
end
|
192
201
|
|
193
202
|
# @param [Hash] env rack env
|
194
|
-
# @return [String] url-scheme://prefix.name.suffix:port/uri/uri/uri?query=query:query=
|
203
|
+
# @return [String] url-scheme://prefix.name.suffix:port/uri/uri/uri?query=query:query=queryrevert master
|
195
204
|
def url env
|
196
205
|
url = "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['REQUEST_URI']}"
|
197
|
-
|
206
|
+
query_string = env['QUERY_STRING'].to_s.strip
|
207
|
+
!query_string.empty? ? url << "?#{query_string}" : url
|
198
208
|
end
|
199
209
|
end
|
200
210
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-logstash-writer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- or garfunkel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|