ping-middleware 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +9 -0
- data/lib/ping-middleware.rb +17 -0
- data/lib/ping-middleware/version.rb +5 -0
- data/ping-middleware.gemspec +19 -0
- data/spec/middleware_spec.rb +42 -0
- metadata +59 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ping-middleware (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rack (1.4.1)
|
10
|
+
rack-client (0.4.0)
|
11
|
+
rack (>= 1.0.0)
|
12
|
+
rake (10.0.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
ping-middleware!
|
19
|
+
rack
|
20
|
+
rack-client
|
21
|
+
rake
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Thorben Schröder
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Ping::Middleware
|
2
|
+
|
3
|
+
Middleware that responds to simple keep alive pings
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Use ``Ping::Middleware`` as a Rack middleware. After that the middleware responds to any request coming in to the ``/__ping__`` path and responds with a HTTP 200 status code and a body which just reads: ``Pong``.
|
8
|
+
|
9
|
+
### Sinatra
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require "ping-middleware"
|
13
|
+
require "sinatra"
|
14
|
+
|
15
|
+
use Ping::Middleware
|
16
|
+
|
17
|
+
get '/' do
|
18
|
+
"hello"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
### Rails
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# config/application.rb
|
26
|
+
|
27
|
+
config.middleware.use Ping::Middleware
|
28
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "ping-middleware/version"
|
2
|
+
|
3
|
+
module Ping
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env['PATH_INFO'] == '/__ping__'
|
11
|
+
[200, {'Content-Type' => 'text/plain'}, ['Pong']]
|
12
|
+
else
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ping-middleware/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ping-middleware"
|
8
|
+
gem.version = Ping::Middleware::VERSION
|
9
|
+
gem.authors = ["Thorben Schröder"]
|
10
|
+
gem.email = ["stillepost@gmail.com"]
|
11
|
+
gem.description = %q{Middleware that responds to simple keep alive pings}
|
12
|
+
gem.summary = %q{Middleware that responds to simple keep alive pings}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
ENV['RACK_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
Bundler.require
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'rack'
|
7
|
+
require 'rack/client'
|
8
|
+
|
9
|
+
describe Ping::Middleware do
|
10
|
+
before do
|
11
|
+
app = Rack::Builder.new do
|
12
|
+
use Ping::Middleware
|
13
|
+
run lambda {|e| [200, {'Content-Type' => 'text/plain'}, ['app']]}
|
14
|
+
end
|
15
|
+
|
16
|
+
@client = Rack::Client.new do
|
17
|
+
run app
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "responds to a ping" do
|
22
|
+
response = @client.get('http://example.com/__ping__')
|
23
|
+
response.status.must_equal 200
|
24
|
+
response.body.must_equal 'Pong'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "runs the rest of the app just fine" do
|
28
|
+
urls = [
|
29
|
+
'http://example.com/__ping_',
|
30
|
+
'http://example.com/_ping__',
|
31
|
+
'http://example.com/ping',
|
32
|
+
'http://example.com/real_url',
|
33
|
+
'http://example.com/'
|
34
|
+
]
|
35
|
+
|
36
|
+
urls.each do |url|
|
37
|
+
response = @client.get(url)
|
38
|
+
response.status.must_equal 200
|
39
|
+
response.body.must_equal 'app'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ping-middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thorben Schröder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Middleware that responds to simple keep alive pings
|
15
|
+
email:
|
16
|
+
- stillepost@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- CHANGELOG.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/ping-middleware.rb
|
30
|
+
- lib/ping-middleware/version.rb
|
31
|
+
- ping-middleware.gemspec
|
32
|
+
- spec/middleware_spec.rb
|
33
|
+
homepage: ''
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Middleware that responds to simple keep alive pings
|
57
|
+
test_files:
|
58
|
+
- spec/middleware_spec.rb
|
59
|
+
has_rdoc:
|