logstash-filter-http 1.4.0 → 1.4.2
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 +6 -0
- data/lib/logstash/filters/http.rb +15 -3
- data/logstash-filter-http.gemspec +1 -1
- data/spec/filters/http_spec.rb +53 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb0e716ca8a625caa16cecf3884f92c979a2fab2b94ff6b868f7b5732da4bd13
|
|
4
|
+
data.tar.gz: a17253287ebce2ad6bd663b60907dd3ec4c8d646cee9dd35901b8bd2d5fad1da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac2c2e11232dbb7d3cc3cc43e3f43cbf2cefcdc71e3f2a7bcb9a421d97a85f96ef75dffa0f1faee97cfb666caae34f75fe87beb161d08fc45a39f7296bd1d9a8
|
|
7
|
+
data.tar.gz: edc975f2862c3a94baa60b1204d0cc5c07c10629f516076c0380d1b8bdb559e6ca0d06d9df08b6191c931007f98db1cb17078aa0dffaeb1252f9e538406cbbc2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 1.4.2
|
|
2
|
+
- Fix: resolve content type when a content-type header contains an array [#46](https://github.com/logstash-plugins/logstash-filter-http/pull/46)
|
|
3
|
+
|
|
4
|
+
## 1.4.1
|
|
5
|
+
- Fix: don't process response body for HEAD requests [#41](https://github.com/logstash-plugins/logstash-filter-http/pull/41)
|
|
6
|
+
|
|
1
7
|
## 1.4.0
|
|
2
8
|
- Feat: added ssl_supported_protocols option [#38](https://github.com/logstash-plugins/logstash-filter-http/pull/38)
|
|
3
9
|
|
|
@@ -88,11 +88,12 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
|
88
88
|
elsif !code.between?(200, 299)
|
|
89
89
|
@logger.error('error during HTTP request',
|
|
90
90
|
:url => url_for_event, :code => code,
|
|
91
|
+
:headers => response_headers,
|
|
91
92
|
:response => response_body)
|
|
92
93
|
@tag_on_request_failure.each { |tag| event.tag(tag) }
|
|
93
94
|
else
|
|
94
95
|
@logger.debug? && @logger.debug('success received',
|
|
95
|
-
:code => code, :body => response_body)
|
|
96
|
+
:code => code, :headers => response_headers, :body => response_body)
|
|
96
97
|
process_response(response_body, response_headers, event)
|
|
97
98
|
filter_matched(event)
|
|
98
99
|
end
|
|
@@ -132,9 +133,10 @@ EOF
|
|
|
132
133
|
end
|
|
133
134
|
|
|
134
135
|
def process_response(body, headers, event)
|
|
135
|
-
content_type, _ = headers.fetch("content-type", "").split(";")
|
|
136
136
|
event.set(@target_headers, headers)
|
|
137
|
-
if
|
|
137
|
+
return if @verb == 'head' # Since HEAD requests will not contain body, we need to set only header
|
|
138
|
+
|
|
139
|
+
if headers_has_json_content_type?(headers)
|
|
138
140
|
begin
|
|
139
141
|
parsed = LogStash::Json.load(body)
|
|
140
142
|
event.set(@target_body, parsed)
|
|
@@ -151,4 +153,14 @@ EOF
|
|
|
151
153
|
end
|
|
152
154
|
end
|
|
153
155
|
|
|
156
|
+
##
|
|
157
|
+
# @param headers [String] or [Array]
|
|
158
|
+
# @return resolved content-type
|
|
159
|
+
def headers_has_json_content_type?(headers)
|
|
160
|
+
# content-type might be an array or string with ; separated
|
|
161
|
+
headers = headers.fetch("content-type", "")
|
|
162
|
+
headers = headers.kind_of?(Array) ? headers : headers.split(';')
|
|
163
|
+
headers.map(&:strip).include?("application/json")
|
|
164
|
+
end
|
|
165
|
+
|
|
154
166
|
end # class LogStash::Filters::Rest
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'logstash-filter-http'
|
|
3
|
-
s.version = '1.4.
|
|
3
|
+
s.version = '1.4.2'
|
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
|
5
5
|
s.summary = 'This filter requests data from a RESTful Web Service.'
|
|
6
6
|
s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install logstash-filter-http. This gem is not a stand-alone program'
|
data/spec/filters/http_spec.rb
CHANGED
|
@@ -118,6 +118,7 @@ describe LogStash::Filters::Http do
|
|
|
118
118
|
'Server' => 'Apache',
|
|
119
119
|
'Last-Modified' => 'Mon, 18 Jul 2016 02:36:04 GMT',
|
|
120
120
|
'X-Backend-Server' => 'logstash.elastic.co',
|
|
121
|
+
'Content-Type' => %w[application/json application/xml]
|
|
121
122
|
}
|
|
122
123
|
[200, response_headers, "Bom dia"]
|
|
123
124
|
end
|
|
@@ -136,10 +137,12 @@ describe LogStash::Filters::Http do
|
|
|
136
137
|
if ecs_select.active_mode == :disabled
|
|
137
138
|
expect(event.get('headers')).to include "Server" => "Apache"
|
|
138
139
|
expect(event.get('headers')).to include "X-Backend-Server" => "logstash.elastic.co"
|
|
140
|
+
expect(event.get('headers')).to include "Content-Type" => %w[application/json application/xml]
|
|
139
141
|
else
|
|
140
142
|
expect(event.include?('headers')).to be false
|
|
141
143
|
expect(event.get('[@metadata][filter][http][response][headers]')).to include "Server" => "Apache"
|
|
142
144
|
expect(event.get('[@metadata][filter][http][response][headers]')).to include "X-Backend-Server" => "logstash.elastic.co"
|
|
145
|
+
expect(event.get('[@metadata][filter][http][response][headers]')).to include "Content-Type" => %w[application/json application/xml]
|
|
143
146
|
end
|
|
144
147
|
end
|
|
145
148
|
|
|
@@ -172,6 +175,46 @@ describe LogStash::Filters::Http do
|
|
|
172
175
|
subject.filter(event)
|
|
173
176
|
end
|
|
174
177
|
end
|
|
178
|
+
|
|
179
|
+
context "content-type header" do
|
|
180
|
+
let(:config) { super().merge "headers" => headers }
|
|
181
|
+
|
|
182
|
+
describe 'when content-type header is an array' do
|
|
183
|
+
let(:headers) {{ "Content-type" => %w[application/json logstash/custom-media-type] }}
|
|
184
|
+
|
|
185
|
+
it "resolves the content-type" do
|
|
186
|
+
expect(subject).to receive(:request_http) do |verb, url, options|
|
|
187
|
+
expect( options.fetch(:headers, {}) ).to include(headers)
|
|
188
|
+
end.and_return(response)
|
|
189
|
+
|
|
190
|
+
expect{ subject.filter(event) }.not_to raise_error
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
describe 'when content-type header is a string' do
|
|
195
|
+
let(:headers) {{ "Content-type" => "application/json; logstash/custom-media-type" }}
|
|
196
|
+
|
|
197
|
+
it "resolves the content-type" do
|
|
198
|
+
expect(subject).to receive(:request_http) do |verb, url, options|
|
|
199
|
+
expect( options.fetch(:headers, {}) ).to include(headers)
|
|
200
|
+
end.and_return(response)
|
|
201
|
+
|
|
202
|
+
expect{ subject.filter(event) }.not_to raise_error
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe 'when content-type header is an empty string' do
|
|
207
|
+
let(:headers) {{ "Content-type" => "" }}
|
|
208
|
+
|
|
209
|
+
it "resolves the content-type" do
|
|
210
|
+
expect(subject).to receive(:request_http) do |verb, url, options|
|
|
211
|
+
expect( options.fetch(:headers, {}) ).to include(headers)
|
|
212
|
+
end.and_return(response)
|
|
213
|
+
|
|
214
|
+
expect{ subject.filter(event) }.not_to raise_error
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
175
218
|
end
|
|
176
219
|
|
|
177
220
|
describe "query string parameters" do
|
|
@@ -191,7 +234,6 @@ describe LogStash::Filters::Http do
|
|
|
191
234
|
before(:each) { subject.register }
|
|
192
235
|
let(:response) { [200, {}, "Bom dia"] }
|
|
193
236
|
let(:url) { "http://stringsize.com" }
|
|
194
|
-
let(:config) { super().merge "body" => body }
|
|
195
237
|
|
|
196
238
|
describe "format" do
|
|
197
239
|
let(:config) { super().merge "body_format" => body_format, "body" => body }
|
|
@@ -277,6 +319,16 @@ describe LogStash::Filters::Http do
|
|
|
277
319
|
subject.filter(event)
|
|
278
320
|
end
|
|
279
321
|
end
|
|
322
|
+
context "when the verb is HEAD" do
|
|
323
|
+
let(:config) { super().merge("verb" => "HEAD") }
|
|
324
|
+
before(:each) do
|
|
325
|
+
allow(subject).to receive(:request_http).and_return(response)
|
|
326
|
+
end
|
|
327
|
+
it "does not include the body" do
|
|
328
|
+
subject.filter(event)
|
|
329
|
+
expect(event).to_not include("body")
|
|
330
|
+
end
|
|
331
|
+
end
|
|
280
332
|
end
|
|
281
333
|
describe "verb" do
|
|
282
334
|
let(:response) { [200, {}, "Bom dia"] }
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logstash-filter-http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elastic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|