logstash-input-http 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7501ef476876913a230b76302468cacc1ffe8dce
4
- data.tar.gz: 84e2a47f556eead137f26baa98e90008141a3869
3
+ metadata.gz: ba514b03f267447315b843c65a676c710300a3ee
4
+ data.tar.gz: f15c517f4ec64213b6c7e3ef95f89a5b6bf88843
5
5
  SHA512:
6
- metadata.gz: c6a1febb7c2895f79a7008278a9589fef2ed92e0f7bcd61c9d22b168d630754824e59c94de62b22c940246967ceb7960f4e57301f589e60b44796835544da4dc
7
- data.tar.gz: 6b52e97baccc26fa8b7cee6c560e2291feb1b6f58648c0cdb6e6c0083dfc5b1f01da972bff966cf0ceef4b625eabfa9faefac93759d9ae371eb5b953960391c7
6
+ metadata.gz: dfc240fde16f8fbac393bda7104bce9f4ef0338d3101fbd72829937fdd35522772e17d0a340757f225234a40662507ec7123886d24c5269918fc9df064f71eef
7
+ data.tar.gz: c1456684b3692f82e5a68f409efd2bb731c1483a048dab507c4d4ae5f2d0911efade13101d5a45a4fa9e2680a79d473c27695df532c95e318389997888b4fc64
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.1.0
2
+ - Support compressed and gziped requests (thanks dwapstra)
3
+
1
4
  ## 2.0.0
2
5
  - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
6
  instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Logstash Plugin
2
2
 
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Inputs/job/logstash-plugin-input-http-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Inputs/job/logstash-plugin-input-http-unit/)
5
+
3
6
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
7
 
5
8
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
@@ -81,6 +81,7 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
81
81
 
82
82
  public
83
83
  def register
84
+ require "logstash/util/http_compressed_requests"
84
85
  @server = ::Puma::Server.new(nil) # we'll set the rack handler later
85
86
  if @user && @password then
86
87
  token = Base64.strict_encode64("#{@user}:#{@password.value}")
@@ -134,6 +135,7 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
134
135
 
135
136
  @server.app = Rack::Builder.new do
136
137
  use(Rack::Auth::Basic, &auth) if auth
138
+ use CompressedRequests
137
139
  run(p)
138
140
  end
139
141
  @server.run.join
@@ -0,0 +1,39 @@
1
+ class CompressedRequests
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def method_handled?(env)
7
+ !!(env['REQUEST_METHOD'] =~ /(POST|PUT)/)
8
+ end
9
+
10
+ def encoding_handled?(env)
11
+ ['gzip', 'deflate'].include? env['HTTP_CONTENT_ENCODING']
12
+ end
13
+
14
+ def call(env)
15
+ if method_handled?(env) && encoding_handled?(env)
16
+ begin
17
+ extracted = decode(env['rack.input'], env['HTTP_CONTENT_ENCODING'])
18
+ rescue Zlib::Error
19
+ return [400, {'Content-Type' => 'text/plain'}, ["Failed to decompress body"]]
20
+ end
21
+
22
+ env.delete('HTTP_CONTENT_ENCODING')
23
+ env['CONTENT_LENGTH'] = extracted.bytesize
24
+ env['rack.input'] = StringIO.new(extracted)
25
+ end
26
+
27
+ @app.call(env)
28
+ end
29
+
30
+ def decode(input, content_encoding)
31
+ case content_encoding
32
+ when 'gzip' then
33
+ Zlib::GzipReader.new(input).read
34
+ when 'deflate' then
35
+ Zlib::Inflate.inflate(input.read)
36
+ end
37
+ end
38
+
39
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-http'
3
- s.version = '2.0.2'
3
+ s.version = '2.1.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Logstash Input plugin that receives HTTP requests"
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/plugin install gemname. This gem is not a stand-alone program"
@@ -3,6 +3,8 @@ require "logstash/inputs/http"
3
3
  require "json"
4
4
  require "ftw"
5
5
  require "stud/temporary"
6
+ require "zlib"
7
+ require "stringio"
6
8
 
7
9
  describe LogStash::Inputs::Http do
8
10
 
@@ -50,6 +52,62 @@ describe LogStash::Inputs::Http do
50
52
  expect(event["message"]).to eq("hello")
51
53
  end
52
54
  end
55
+ context "when receiving a deflate compressed text/plain request" do
56
+ it "should process the request normally" do
57
+ subject.register
58
+ Thread.new { subject.run(queue) }
59
+ agent.post!("http://localhost:#{port}/meh.json",
60
+ :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
61
+ :body => Zlib::Deflate.deflate("hello"))
62
+ event = queue.pop
63
+ expect(event["message"]).to eq("hello")
64
+ end
65
+ end
66
+ context "when receiving a deflate text/plain request that cannot be decompressed" do
67
+ let!(:response) do
68
+ subject.register
69
+ Thread.new { subject.run(queue) }
70
+ agent.post!("http://localhost:#{port}/meh.json",
71
+ :headers => { "content-type" => "text/plain", "content-encoding" => "deflate" },
72
+ :body => "hello")
73
+ end
74
+ it "should respond with 400" do
75
+ expect(response.status).to eq(400)
76
+ end
77
+ it "should respond with a decompression error" do
78
+ expect(response.read_body).to eq("Failed to decompress body")
79
+ end
80
+ end
81
+ context "when receiving a gzip compressed text/plain request" do
82
+ it "should process the request normally" do
83
+ subject.register
84
+ Thread.new { subject.run(queue) }
85
+ z = StringIO.new ""
86
+ w = Zlib::GzipWriter.new z;
87
+ w.write("hello");
88
+ w.finish;
89
+ agent.post!("http://localhost:#{port}/meh.json",
90
+ :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
91
+ :body => z.string)
92
+ event = queue.pop
93
+ expect(event["message"]).to eq("hello")
94
+ end
95
+ end
96
+ context "when receiving a gzip text/plain request that cannot be decompressed" do
97
+ let!(:response) do
98
+ subject.register
99
+ Thread.new { subject.run(queue) }
100
+ agent.post!("http://localhost:#{port}/meh.json",
101
+ :headers => { "content-type" => "text/plain", "content-encoding" => "gzip" },
102
+ :body => "hello")
103
+ end
104
+ it "should respond with 400" do
105
+ expect(response.status).to eq(400)
106
+ end
107
+ it "should respond with a decompression error" do
108
+ expect(response.read_body).to eq("Failed to decompress body")
109
+ end
110
+ end
53
111
  context "when receiving an application/json request" do
54
112
  it "should parse the json body" do
55
113
  subject.register
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +127,7 @@ files:
127
127
  - NOTICE.TXT
128
128
  - README.md
129
129
  - lib/logstash/inputs/http.rb
130
+ - lib/logstash/util/http_compressed_requests.rb
130
131
  - logstash-input-http.gemspec
131
132
  - spec/inputs/http_spec.rb
132
133
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html