logstash-filter-http 1.4.1 → 1.4.3

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: cf9e6e5719322e393443523446a54d9940048cd2dc540d4f71afedf7dd58b1dd
4
- data.tar.gz: 72869368a417ccc28e522ab0ef47a3910d3bdb8565a9c215108a3cc3d8f088ca
3
+ metadata.gz: 115c2c25afb8de24c53df0f55cd72b9a4e02d1fd6536a2eb8e5450c0ba4830df
4
+ data.tar.gz: 6c2dcab69cdae94dc7c98aeca7ff023451ba681d674b813e575b6f5c68ee8edd
5
5
  SHA512:
6
- metadata.gz: 2c76225e97cc973becbace99e5f2af1cbbebcdc73d264e735dc6064b5d7d1ecd88a51f0665bed3df2c6571d209c61ffa044be69f009762454713d367f96e653b
7
- data.tar.gz: 2cffbf09fc61fd9a0fc7594e7f828497e9c8e098e056053c8791a2d9bb16533cedf2b31f3cf934f1bd5cc40e9d2574f007895a90ff469d962fb4a6d6f19eec52
6
+ metadata.gz: b4b38e4785d4a4674511d62b62f02caf7f161cb0523d2991aa375066c9c16b0c1323726a691b543dd614d9bcf6eccf291072548bd61617d63b031a59752a138a
7
+ data.tar.gz: 62b3b7e17e567cb4aefd648bb25629f2c1c1b5c87ba008d4259fdf70078f8e5c2ede799f0c6339f7acb89a9692fff7e7c3c869d87514947ab0ce8ec00c818a1b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
+ ## 1.4.3
2
+ - DOC: add clarification on sending data as json [#48](https://github.com/logstash-plugins/logstash-filter-http/pull/48)
3
+
4
+ ## 1.4.2
5
+ - Fix: resolve content type when a content-type header contains an array [#46](https://github.com/logstash-plugins/logstash-filter-http/pull/46)
6
+
1
7
  ## 1.4.1
2
- - Fix: don't process response body for HEAD requests [#40](https://github.com/logstash-plugins/logstash-filter-http/pull/40)
8
+ - Fix: don't process response body for HEAD requests [#41](https://github.com/logstash-plugins/logstash-filter-http/pull/41)
3
9
 
4
10
  ## 1.4.0
5
11
  - Feat: added ssl_supported_protocols option [#38](https://github.com/logstash-plugins/logstash-filter-http/pull/38)
@@ -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,10 +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
137
  return if @verb == 'head' # Since HEAD requests will not contain body, we need to set only header
138
- if content_type == "application/json"
138
+
139
+ if headers_has_json_content_type?(headers)
139
140
  begin
140
141
  parsed = LogStash::Json.load(body)
141
142
  event.set(@target_body, parsed)
@@ -152,4 +153,14 @@ EOF
152
153
  end
153
154
  end
154
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
+
155
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.1'
3
+ s.version = '1.4.3'
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'
@@ -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
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.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement