logstash-input-http 2.0.2 → 2.1.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 +3 -0
- data/README.md +3 -0
- data/lib/logstash/inputs/http.rb +2 -0
- data/lib/logstash/util/http_compressed_requests.rb +39 -0
- data/logstash-input-http.gemspec +1 -1
- data/spec/inputs/http_spec.rb +58 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba514b03f267447315b843c65a676c710300a3ee
|
4
|
+
data.tar.gz: f15c517f4ec64213b6c7e3ef95f89a5b6bf88843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
[](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.
|
data/lib/logstash/inputs/http.rb
CHANGED
@@ -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
|
data/logstash-input-http.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-http'
|
3
|
-
s.version = '2.0
|
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"
|
data/spec/inputs/http_spec.rb
CHANGED
@@ -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
|
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:
|
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
|